{"id":12174,"date":"2020-05-20T10:32:44","date_gmt":"2020-05-20T17:32:44","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12174"},"modified":"2023-12-01T02:47:43","modified_gmt":"2023-12-01T10:47:43","slug":"python-collections","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-collections\/","title":{"rendered":"Python Collections: A Step-By-Step Guide"},"content":{"rendered":"\n<p><em>Python has four data collection types:  lists, tuples, sets, and dictionaries. The collections Python module provides additional options, including <\/em><code><em>namedtuple<\/em><\/code><em>, <\/em><code><em>Counter<\/em><\/code><em>, <\/em><code><em>defaultdict<\/em><\/code><em>, and <\/em><code><em>ChainMap<\/em><\/code><em>.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Python offers four collection data types: lists, tuples, sets, and dictionaries. Each of these data types is useful in specific situations.&nbsp;<\/p>\n\n\n\n<p>For example, because lists can be modified, you may want to use one to store an evolving list of student names. Or suppose you want to store a list of ice cream flavors that will never change. A tuple, whose contents cannot be modified, may be more appropriate.<\/p>\n\n\n\n<p>Often, when you\u2019re working in Python, you may find that these data types do not offer all the features you\u2019re looking for. Luckily, there is a Python module that you can use to access more advanced features related to collections of data: the Python collections module.<\/p>\n\n\n\n<p>The Python collections module was created to improve the functionality of built-in collection options and to give developers more flexibility when working with data structures. In this guide, we will break down the basics of the Python collections module and explore four of the most commonly used data structures from the module.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Collections Refresher<\/h2>\n\n\n\n<p>Collections are container data types that can be used to store data. As discussed earlier, collections can store lists, sets, tuples, and dictionaries. Each of these data types has its own characteristics.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lists<\/h3>\n\n\n\n<p>A <a href=\"https:\/\/careerkarma.com\/blog\/python-list-methods\">list<\/a> is an ordered, mutable data type that can be used to store data that may change over time. For example, you can add, remove, and update existing list items. Lists can contain duplicate values. You can use index numbers to reference individual items within a list.<\/p>\n\n\n\n<p>The following is an example of declaring a list in Python:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>sandwiches = [\"Cheese\", \"Ham\", \"Tuna\", \"Egg Mayo\"]<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Tuples<\/h3>\n\n\n\n<p><a href=\"https:\/\/careerkarma.com\/blog\/python-tuples\">Tuples<\/a> are ordered and immutable data types. Although tuples can contain duplicate values, their values cannot be changed. Tuples are surrounded by curly brackets.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s an example of a Python tuple:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>sandwiches = (\"Cheese\", \"Ham\", \"Tuna\", \"Egg Mayo\")<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Sets<\/h3>\n\n\n\n<p>Sets are unordered lists. They are declared using square brackets. Unlike lists, sets do not have index values and cannot include duplicate entries.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s an example of a Python set:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>sandwiches = {\"Cheese\", \"Ham\", \"Tuna\", \"Egg Mayo\"}<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Dictionaries<\/h3>\n\n\n\n<p>Dictionaries are unordered, changeable data types that can be indexed. Each item in a dictionary has a key and a value.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s an example of a Python dictionary entry:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>sandwich = {\n\t\"name\": \"Cheese\",\n\t\"price\": 8.95\n}<\/pre><\/div>\n\n\n\n<p>These four data types have a wide variety of uses in Python. However, if you\u2019re looking to perform more advanced actions with Python container data types, the Python collections module is worth considering.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Collections Module<\/h2>\n\n\n\n<p>The Python collections module contains a number of specialized data structures that you can use in addition to\u2014or as an alternative to\u2014Python\u2019s built-in containers. Because <code>collections<\/code> is a module, we have to import it into our program. However it is built into Python, so we do not need to import secondary libraries.<\/p>\n\n\n\n<p>In this article, we will focus on the four most commonly used data structures from the collections module. These are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Counter<\/li>\n\n\n\n<li>namedtuple<\/li>\n\n\n\n<li>defaultdict<\/li>\n\n\n\n<li>ChainMap<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Counter<\/h3>\n\n\n\n<p><code>Counter()<\/code> is a subclass of the dictionary object and can be used to count hashable objects. The <code>Counter()<\/code> function takes in an iterable as an argument and returns a dictionary.<\/p>\n\n\n\n<p>So, let\u2019s say that we have a list of sandwich orders for January and want to know how many BLT sandwiches we sold during that month. We could use the <code>Counter()<\/code> function to do this.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s an example of the code we would use:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>from collections import Counter\nsandwich_sales = [\"BLT\", \"Egg Mayo\", \"Ham\", \"Ham\", \"Ham\", \"Cheese\", \"BLT\", \"Cheese\"]\nour_counter = Counter(sandwich_sales)\nprint(our_counter[\"BLT\"])<\/pre><\/div>\n\n\n\n<p>Our program returns: <code>2<\/code>. <\/p>\n\n\n\n<p>There is a lot going on in our code, so let\u2019s break it down.<\/p>\n\n\n\n<p>On the first line, we import the <code>Counter<\/code> function from <code>collections<\/code>. We have to do this because <code>collections<\/code> is a module. Then, we declare our <code>sandwich_sales<\/code> array, which stores how many sandwiches we sold in January.<\/p>\n\n\n\n<p>On the next line, we declare the <code>our_counter<\/code> variable and assign it the <code>Counter(sandwich_sales)<\/code> function. This allows us to access the result of the <code>Counter()<\/code> function when we reference <code>our_counter<\/code>.<\/p>\n\n\n\n<p>Finally, we use <code>print(our_counter[\u201cBLT\u201d])<\/code> to print out how many sandwiches in our dictionary are equal to <code>BLT<\/code>. In this case, the answer was <code>2<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">namedtuple<\/h3>\n\n\n\n<p>The <code>namedtuple()<\/code> method returns a tuple with names for each position in the tuple. When you\u2019re working with a standard tuple, the only way you can access individual values is by referencing the tuple\u2019s index numbers. If you\u2019re working with a big tuple, this can quickly get confusing.<\/p>\n\n\n\n<p>Here\u2019s an example of using the <code>namedtuple()<\/code> method to store a sandwich\u2019s name and price:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>from collections import namedtuple\nSandwich = namedtuple(\"Sandwich\", \"name, price\")\nfirst_sandwich = Sandwich(\"Chicken Teriyaki\", \"$3.00\")\nprint(first_sandwich.price)<\/pre><\/div>\n\n\n\n<p>Our program returns: <code>$3.00<\/code>.<\/p>\n\n\n\n<p>There\u2019s a lot going on in our code, so let\u2019s break it down. On the first line, we import <code>namedtuple<\/code> from the <code>collections<\/code> module so that we can use it in our code.<\/p>\n\n\n\n<p>On the next line, we create the Sandwich tuple with the name <code>Sandwich<\/code>, and assign it two headers: name and price. This allows us to use these headers to reference the values in our tuples later on in our code. Next, we declare a variable called <code>first_sandwich<\/code>, which is we assigned the tuple item <code>Chicken Teriyaki<\/code>.<\/p>\n\n\n\n<p>Finally, we print out the price of our <code>first_sandwich<\/code>, which in this case is $3.00.<\/p>\n\n\n\n<p>You can also create a <code>namedtuple()<\/code> using a list. Here\u2019s an example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>second_sandwich = Sandwich._make([\"Spicy Italian\", \"$3.75\"])\nprint(second_sandwich.name)<\/pre><\/div>\n\n\n\n<p>Our program returns: <code>Spicy Italian<\/code>. In this example, we use <code>_make<\/code> in addition to our <code>Sandwich<\/code> item to denote that we want to turn our list into a <code>namedtuple()<\/code>.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">defaultdict<\/h3>\n\n\n\n<p>The <code>defaultdict()<\/code> method can be used to create a Python dictionary that does not throw a KeyError when you try to access an object that does not exist. Instead, if you reference an object that does not exist, the dictionary will return a predefined data type.<\/p>\n\n\n\n<p>Here\u2019s an example that uses the <code>defaultdict()<\/code> method to declare a dictionary that will return an <code>str<\/code> if we reference a non-existent object:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>from collections import defaultdict\nsandwiches = defaultdict(str)\nsandwiches[0] = \"Ham and Cheese\"\nsandwiches[1] = \"BLT\"\nprint(sandwiches[1])\nprint(sandwiches[2])<\/pre><\/div>\n\n\n\n<p>Our program returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>BLT\n\/\/ This is a blank line<\/pre><\/div>\n\n\n\n<p>In the above example, we created a dictionary with values at index positions <code>0<\/code> and <code>1<\/code>. When we print out <code>sandwiches[1]<\/code>, we can see that our dictionary stored our values. However, when we try to print out the item associated with the index value <code>2<\/code>, our program returns a blank line because there is no value assigned to that index.<\/p>\n\n\n\n<p>In a standard dictionary, our program would return a KeyError. However, because we used <code>defaultdict<\/code>, our program instead returns the data type we specified when we created the dictionary. In the above example, we stated that any invalid key should return an <code>str<\/code>, but we could have coded it to return an integer or any other valid data type.<\/p>\n\n\n\n<p>This function can be useful when you\u2019re working with a dictionary to perform an operation on multiple items but the operation may not work on each item. Instead of causing your program to return an error, the <code>defaultdict()<\/code> will return a default value and keep running.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ChainMap<\/h3>\n\n\n\n<p>The <code>ChainMap()<\/code> method is used to combine two or more dictionaries; it returns a list of dictionaries. For example, let\u2019s say that we have two menus\u2014a standard menu and a secret menu\u2014that we want to merge into one big menu. In order to do this, we could use the <code>ChainMap()<\/code> function.<\/p>\n\n\n\n<p>Here\u2019s an example of using <code>ChainMap()<\/code> to merge our standard and secret menus:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>from collections import ChainMap\nstandard_menu = { \"BLT\": \"$3.05\", \"Roast Beef\": \"$3.55\", \"Cheese\": \"$2.85\", \"Shrimp\": \"$3.55\", \"Ham\": \"$2.85\" }\nsecret_menu = { \"Steak\": \"$3.60\", \"Tuna Special\": \"$3.20\", \"Turkey Club\": \"$3.20\" }\nmenu = ChainMap(standard_menu, secret_menu)\nprint(menu)<\/pre><\/div>\n\n\n\n<p>Our code returns a ChainMap object that merged our two menus together, as follows: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ChainMap({'BLT': '$3.05', 'Roast Beef': '$3.55', 'Cheese': '$2.85', 'Shrimp': '$3.55', 'Ham': '$2.85'}, {'Steak': '$3.60', 'Tuna Special': '$3.20', 'Turkey Club': '$3.20'})<\/pre><\/div>\n\n\n\n<p>We can access each value in our ChainMap by referencing its key name. For example, here\u2019s a line of code that allows us to retrieve the price of the BLT sandwich: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(menu[\"BLT\"])<\/pre><\/div>\n\n\n\n<p>Our program returns: $3.05<\/p>\n\n\n\n<p>In addition, it\u2019s important to note that ChainMap updates when the dictionaries it contains are updated. So, if you change a value in the <code>standard_menu<\/code> or <code>secret_menu<\/code> dictionaries, the ChainMap object will also be updated. Here\u2019s an example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(menu)\nstandard_menu[\"BLT\"] = \"$3.10\"\nprint(menu)<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ChainMap({'BLT': '$3.10', 'Roast Beef': '$3.55', 'Cheese': '$2.85', 'Shrimp': '$3.55', 'Ham': '$2.85'}, {'Steak': '$3.60', 'Tuna Special': '$3.20', 'Turkey Club': '$3.20'})<\/pre><\/div>\n\n\n\n<p>As you can see, the price of our BLT changed from $3.05 to $3.10 because we changed its price in our <code>standard_menu<\/code> dictionary.<\/p>\n\n\n\n<p>The ChainMap object also includes two functions that can be used to retrieve the keys or values from an object. We can illustrate this using the <code>keys()<\/code> and <code>values()<\/code> methods. These methods return the keys of our data (which we can use to reference a particular value) and the values they have been assigned:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(list(menu.keys()))\nprint(list(menu.values()))<\/pre><\/div>\n\n\n\n<p>Our code returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>['Steak', 'Tuna Special', 'Turkey Club', 'BLT', 'Roast Beef', 'Cheese', 'Prawn', 'Ham']\n['$3.60', '$3.20', '$3.20', '$3.05', '$3.55', '$2.85', '$3.55', '$2.85']<\/pre><\/div>\n\n\n\n<p>Our code returned the keys and values of each item in our ChainMap object when we used the <code>keys()<\/code> and <code>values()<\/code> methods above.<\/p>\n\n\n\n<p>In addition, you can add a new dictionary to a ChainMap object using the <code>new_child()<\/code> method. Let\u2019s say that our sandwich chef has been trying out new sandwiches on a test menu and wants to add two of them to our new menu. We could use the following code to achieve this goal:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>test_menu = { \"Veggie Deluxe\": \"$3.00\", \"House Club Special\": \"$3.65\" }\nnew_menu = menu.new_child(test_menu)\nprint(new_menu)<\/pre><\/div>\n\n\n\n<p>Our code returns an updated ChainMap with our new sandwiches at the start of the dictionary, as follows: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ChainMap({'Veggie Deluxe': '$3.00', 'House Club Special': '$3.65'}, {'BLT': '$3.05', 'Roast Beef': '$3.55', 'Cheese': '$2.85', 'Shrimp': '$3.55', 'Ham': '$2.85'}, {'Steak': '$3.60', 'Tuna Special': '$3.20', 'Turkey Club': '$3.20'})<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>We can use the Python collections module to extend the built-in collections offered by Python and to access custom data structure methods. This is helpful if you are looking to work with a collection data type, such as a list or a tuple, but need to perform a certain function that does not come in vanilla (or <code>plain<\/code>) Python.<\/p>\n\n\n\n<p>In this guide, using examples, we broke down how to use collections in Python and discussed the four main methods offered by the library: <code>Counter<\/code>, <code>namedtuple<\/code>, <code>defaultdict<\/code>, and <code>ChainMap<\/code>.&nbsp;<\/p>\n\n\n\n<p>Now you\u2019re equipped with the knowledge you need to start working with the Python collections module like an expert!<\/p>\n\n\n\n<p><strong><em>Are you curious to know how learning Python can help you break into a career in tech? Download the <a href=\"https:\/\/careerkarma.com\/\">free Career Karma app<\/a> today and talk with one of our expert career coaches!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"Python has four data collection types: lists, tuples, sets, and dictionaries. The collections Python module provides additional options, including namedtuple, Counter, defaultdict, and ChainMap. Python offers four collection data types: lists, tuples, sets, and dictionaries. Each of these data types is useful in specific situations.&nbsp; For example, because lists can be modified, you may want&hellip;","protected":false},"author":240,"featured_media":11485,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[12687],"class_list":{"0":"post-12174","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"tag-tutorial"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Collections: A Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The Python collections module to improves on built-in Python container data types. Learn about how to use the collections module on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-collections\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Collections: A Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"The Python collections module to improves on built-in Python container data types. Learn about how to use the collections module on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-collections\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-20T17:32:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:47:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python Collections: A Step-By-Step Guide\",\"datePublished\":\"2020-05-20T17:32:44+00:00\",\"dateModified\":\"2023-12-01T10:47:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/\"},\"wordCount\":1574,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg\",\"keywords\":[\"tutorial\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-collections\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-collections\/\",\"name\":\"Python Collections: A Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg\",\"datePublished\":\"2020-05-20T17:32:44+00:00\",\"dateModified\":\"2023-12-01T10:47:43+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The Python collections module to improves on built-in Python container data types. Learn about how to use the collections module on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-collections\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-collections\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Collections: A Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Collections: A Step-By-Step Guide | Career Karma","description":"The Python collections module to improves on built-in Python container data types. Learn about how to use the collections module on Career Karma.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-collections\/","og_locale":"en_US","og_type":"article","og_title":"Python Collections: A Step-By-Step Guide","og_description":"The Python collections module to improves on built-in Python container data types. Learn about how to use the collections module on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/python-collections\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-05-20T17:32:44+00:00","article_modified_time":"2023-12-01T10:47:43+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-collections\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python Collections: A Step-By-Step Guide","datePublished":"2020-05-20T17:32:44+00:00","dateModified":"2023-12-01T10:47:43+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-collections\/"},"wordCount":1574,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg","keywords":["tutorial"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-collections\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-collections\/","url":"https:\/\/careerkarma.com\/blog\/python-collections\/","name":"Python Collections: A Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg","datePublished":"2020-05-20T17:32:44+00:00","dateModified":"2023-12-01T10:47:43+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The Python collections module to improves on built-in Python container data types. Learn about how to use the collections module on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-collections\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/wbZxWEyswj7Eo9Z91NDRAWjK9n9Ehe4r1WnzTdvM1pZRztN1FBHnShLeMkv-HDdaPHOHcVTsoP5sqfQJS2XWJ92okcdsXnb8yY9dNpswDel-SFPMPShnmdgn7qDEx7u3Tta2dvWz.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-collections\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Collections: A Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12174"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12174\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/11485"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}