{"id":17668,"date":"2020-06-01T03:58:33","date_gmt":"2020-06-01T10:58:33","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=17668"},"modified":"2023-12-01T03:05:25","modified_gmt":"2023-12-01T11:05:25","slug":"python-sets","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-sets\/","title":{"rendered":"Python Sets: A Guide"},"content":{"rendered":"\n<p>Often, when you\u2019re working with data, you\u2019ll want to store a list of data that cannot contain any duplicate values, and whose values cannot be changed. For instance, if you\u2019re making a list of purchase IDs at a grocery store, you would want each ID to be unique, and you would not want anyone to be able to change the values in your list.<br><\/p>\n\n\n\n<p>That\u2019s where the Python set object comes in. A set is an unordered collection of items that can only contain unique values.<br><\/p>\n\n\n\n<p>This tutorial will discuss, with reference to examples, the basics of Python sets, and how you can perform common operations like adding and removing values on a set.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Sets<\/h2>\n\n\n\n<p>The Python built-in set data structure is similar to the idea of sets in mathematics.<br><\/p>\n\n\n\n<p>Python sets can contain zero or more elements, and there is no defined order for each element in the set. Every element stored within a set is unique, so no duplicates can exist, and each individual value in the set cannot be changed.<br><\/p>\n\n\n\n<p>Although individual values in a set cannot be changed, the set itself can be. This means that we can add or remove items from our set.<br><\/p>\n\n\n\n<p>The set structure is useful because it comes with a number of mathematical operations that we can use to work with the data we have stored in a set.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Python Set<\/h2>\n\n\n\n<p>In Python, sets are defined as a list of items (or \u201celements\u201d) that are separated by commas. The list is then enclosed within curly braces ({}).<br><\/p>\n\n\n\n<p>Python sets can store any number of items, and each item within a set can use different data types. So, a set can store both an integer or a string, or a string, float, and a tuple. However, sets cannot store mutable data types, like another set, a dictionary, or a list.<br><\/p>\n\n\n\n<p>Suppose we want to create a set that stores a list of homework assignments a student has handed in for an English class. We could create this set using the following code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {\"Worksheet #4\", \"Worksheet #5\", \"Worksheet #7\", \"End of Topic Review #2\"}\nprint(assignments)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;Worksheet #5&#8217;, &#8216;Worksheet #4&#8217;, &#8216;Worksheet #7&#8217;, &#8216;End of Topic Review #2&#8217;}<br><\/p>\n\n\n\n<p>In our code, we defined a set called <code>assignments<\/code> which has four values. Then, we printed out the contents of the assignment set to the console. You can see that our values are returned in a random order because sets do not store their items in any particular order.&nbsp;<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Changing a Set<\/h2>\n\n\n\n<p>When you have created a set, you cannot change the values of the items in the set. However, you can add items to and remove items from a set.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Add Items to a Set<\/h3>\n\n\n\n<p>To add an element to a Python set, you can use the <code>add() <\/code>method. Suppose a student has just handed in <code>Worksheet #8<\/code> and we want to update our set to keep track of the student\u2019s assignment being handed in. We could do so using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {\"Worksheet #4\", \"Worksheet #5\", \"Worksheet #7\", \"End of Topic Review #2\"}\nassignments.add(\"Worksheet #8\")\nprint(assignments)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;Worksheet #8&#8217;, &#8216;Worksheet #4&#8217;, &#8216;Worksheet #5&#8217;, &#8216;End of Topic Review #2&#8217;, &#8216;Worksheet #7&#8217;}<br><\/p>\n\n\n\n<p>As you can see, <code>Worksheet #8<\/code> has been added to our set.<br><\/p>\n\n\n\n<p>In addition, if you want to add multiple items to a set, you can use the <code>update()<\/code> method. The <code>update() <\/code>method accepts a list of items to which you want to add to a set as a parameter, then adds those items to a set.<br><\/p>\n\n\n\n<p>Suppose a student has handed in both worksheets #8 and #9. We could change our set to reflect these new assignments being handed in using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {\"Worksheet #4\", \"Worksheet #5\", \"Worksheet #7\", \"End of Topic Review #2\"}\nassignments.update([\"Worksheet #8\", \"Worksheet #9\"])\nprint(assignments)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;Worksheet #9&#8217;, &#8216;End of Topic Review #2&#8217;, &#8216;Worksheet #8&#8217;, &#8216;Worksheet #7&#8217;, &#8216;Worksheet #4&#8217;, &#8216;Worksheet #5&#8217;}<br><\/p>\n\n\n\n<p>Now our set contains two new values: <code>Worksheet #8<\/code> and <code>Worksheet #9<\/code>.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Remove Elements from a Set<\/h3>\n\n\n\n<p>To remove an element from a set, you can use <code>discard()<\/code> or <code>remove()<\/code>.<br><\/p>\n\n\n\n<p>The <code>discard()<\/code> function removes an item from a set and returns nothing if an item does not exist in a set. The <code>remove() <\/code>function will attempt to remove an item from a set, and if that item does not exist, an error will be raised.<br><\/p>\n\n\n\n<p>Suppose we want to remove <code>Worksheet #9<\/code> from our record of a student\u2019s homework assignments because they have been asked to re-do the assignment. We could do so using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {'Worksheet #9', 'End of Topic Review #2', 'Worksheet #8', 'Worksheet #7', 'Worksheet #4', 'Worksheet #5'}\nassignments.discard(\"Worksheet #9\")\nprint(assignments)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;End of Topic Review #2&#8217;, &#8216;Worksheet #5&#8217;, &#8216;Worksheet #4&#8217;, &#8216;Worksheet #8&#8217;, &#8216;Worksheet #7&#8217;}<br><\/p>\n\n\n\n<p>You can see that the value <code>Worksheet #9<\/code> has been removed from our set. We accomplished this using the <code>discard()<\/code> method.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Clear a Set<\/h3>\n\n\n\n<p>To clear a set, you can use the <code>clear()<\/code> method. Suppose we want to erase a record of a student\u2019s assignments because it is the end of the year and we no longer need to store the information. We could do so using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {'Worksheet #9', 'End of Topic Review #2', 'Worksheet #8', 'Worksheet #7', 'Worksheet #4', 'Worksheet #5'}\nassignments.clear()\nprint(assignments)\n<\/pre><\/div>\n\n\n\n<p>Our code returns: {}. This reflects our empty set.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Return Length of a Set<\/h2>\n\n\n\n<p>To find out how many items are stored in a set, you can use the <code>len() <\/code>method.<br><\/p>\n\n\n\n<p>Suppose we want to find out how many homework assignments a student has handed in. We could do so using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {'Worksheet #9', 'End of Topic Review #2', 'Worksheet #8', 'Worksheet #7', 'Worksheet #4', 'Worksheet #5'}\nprint(len(assignments))\n<\/pre><\/div>\n\n\n\n<p>Our code returns: 6. In our code, we first declare a set called <code>assignments<\/code>. Then, we use the <code>len()<\/code> method to find out how many items are stored in the <code>assignments<\/code> set.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Set Operations<\/h2>\n\n\n\n<p>One of the advantages of using a set to store data is that sets support mathematical set operations. Let\u2019s walk through how three of the main set operations work.<br><\/p>\n\n\n\n<p>These set operations <strong>do not change<\/strong> the contents of a set. Instead, they perform a calculation on an existing set.<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Set Union<\/h3>\n\n\n\n<p>The <code>union()<\/code> method allows us to create a set of all elements from two sets.<br><\/p>\n\n\n\n<p>Suppose we have two lists of a student\u2019s assignments that we want to merge together. One list contains data on a student\u2019s homework, and the other contains a list of the essay assignments a student has completed. We could merge these lists using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {\"Worksheet #4\", \"Worksheet #5\", \"Worksheet #7\"}\nessays = {\"Essay #1\", \"Essay #2\"}\nhomework = assignments.union(essays)\nprint(homework)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;Worksheet #7&#8217;, &#8216;Essay #2&#8217;, &#8216;Worksheet #4&#8217;, &#8216;Essay #1&#8217;, &#8216;Worksheet #5&#8217;}<br><\/p>\n\n\n\n<p>In our code, we use the <code>union()<\/code> method to merge our two sets together. We assign the value of the newly-merged set to the variable <code>homework<\/code>. Then, we printed out the value of the <code>homework<\/code> variable.<br><\/p>\n\n\n\n<p>Alternatively, we could have used the following code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>assignments = {\"Worksheet #4\", \"Worksheet #5\", \"Worksheet #7\"}\nessays = {\"Essay #1\", \"Essay #2\"}\nprint(assignments | essays)\n<\/pre><\/div>\n\n\n\n<p>The \u201c|\u201d operator performs a union set operation. Our code returns a merged set:<br><\/p>\n\n\n\n<p>{&#8216;Essay #2&#8217;, &#8216;Worksheet #4&#8217;, &#8216;Worksheet #5&#8217;, &#8216;Essay #1&#8217;, &#8216;Worksheet #7&#8217;}<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Set Intersection<\/h3>\n\n\n\n<p>The <code>intersection() <\/code>method allows you to generate a list of elements that are common between two sets.<br><\/p>\n\n\n\n<p>Suppose we have a list of essays a student has handed in, and a list of essays that have been issued. If we wanted to know which essays a student has not yet handed in, we could perform an intersection method.<br><\/p>\n\n\n\n<p>Here\u2019s the code we would use:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>essays_handed_in = {\"Essay #1\", \"Essay #2\"}\nessays_issued = {\"Essay #1\", \"Essay #2\", \"Essay #3\"}\ndue = essays_handed_in.intersection(essays_issued)\nprint(due)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;Essay #1&#8217;, &#8216;Essay #2&#8217;}<br><\/p>\n\n\n\n<p>In this example, we use the <code>intersection()<\/code> method to find all elements that exist in both the <code>essays_handed_in<\/code> and <code>essays_issued<\/code> sets. We assign the result of the intersection operation to the variable <code>due<\/code>, which we then print to the console.<br><\/p>\n\n\n\n<p>In addition, we can use the <code>&amp;<\/code> operator to perform a set intersection operation. So, if we wanted to perform an intersection on our two sets from earlier, we could use this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>essays_handed_in = {\"Essay #1\", \"Essay #2\"}\nessays_issued = {\"Essay #1\", \"Essay #2\", \"Essay #3\"}\nprint(essays_handed_in &amp; essays_issued)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{&#8216;Essay #1&#8217;, &#8216;Essay #2&#8217;}<br><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Set Difference<\/h3>\n\n\n\n<p>The <code>difference()<\/code> method allows you to find out which elements are present in one set that are not present in another set.<br><\/p>\n\n\n\n<p>Suppose we wanted to generate a list of all essays that a student has handed in and that have not yet been graded. We could do so using this code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>essays_handed_in = {\"Essay #1\", \"Essay #2\"}\nessays_graded = {\"Essay #1\"}\nfinal = essays_handed_in.difference(essays_graded)\nprint(final)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{\u201cEssay #2\u201d}<br><\/p>\n\n\n\n<p>In this code, we used the <code>difference()<\/code> method to find the difference between the <code>essays_handed_in<\/code> and <code>essays_graded<\/code> sets. Alternatively, we could use the <code>-<\/code> operator, like so:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>essays_handed_in = {\"Essay #1\", \"Essay #2\"}\nessays_graded = {\"Essay #1\"}\nprint(essays_handed_in - essays_graded)\n<\/pre><\/div>\n\n\n\n<p>Our code returns:<br><\/p>\n\n\n\n<p>{\u201cEssay #2\u201d}<br><\/p>\n\n\n\n<p>The same result is returned in our code. But instead of using the <code>difference() <\/code>set method, we used the <code>-<\/code> operator, which performs a check to find the difference between two sets.<br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The Python set data structure allows you to store unordered collections of items.<br><\/p>\n\n\n\n<p>Each item in a set must be unique, so no duplicates can exist, and the contents of a set cannot be changed once they are added to the set.<br><\/p>\n\n\n\n<p>This tutorial discussed, with reference to examples, the basics of Python sets and the main operations offered by sets.<br><\/p>\n\n\n\n<p>We only scratched the surface of what you can do with sets, though\u2014there\u2019s still more for you to explore\u2014but we did cover the main skills you need to know to effectively work with sets. Now you\u2019re ready to start using the Python <code>set()<\/code> method like a pro!<\/p>\n\n\n\n<p><br><strong><em>Python is used in professional development environments around the world for everything from data analysis to web development. Download the <\/em><\/strong><a href=\"https:\/\/careerkarma.com\/\"><strong><em>free Career Karma app<\/em><\/strong><\/a><strong><em> today to learn more about career paths in Python programming.<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"Often, when you\u2019re working with data, you\u2019ll want to store a list of data that cannot contain any duplicate values, and whose values cannot be changed. For instance, if you\u2019re making a list of purchase IDs at a grocery store, you would want each ID to be unique, and you would not want anyone to&hellip;","protected":false},"author":240,"featured_media":17670,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-17668","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"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 Sets: A Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"A set is an unordered collection of data that cannot store duplicate values, and whose values cannot be changed. On Career Karma, learn how to work with Python sets.\" \/>\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-sets\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Sets: A Guide\" \/>\n<meta property=\"og:description\" content=\"A set is an unordered collection of data that cannot store duplicate values, and whose values cannot be changed. On Career Karma, learn how to work with Python sets.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-sets\/\" \/>\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-06-01T10:58:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:05:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.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-sets\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python Sets: A Guide\",\"datePublished\":\"2020-06-01T10:58:33+00:00\",\"dateModified\":\"2023-12-01T11:05:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/\"},\"wordCount\":1432,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-sets\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-sets\/\",\"name\":\"Python Sets: A Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg\",\"datePublished\":\"2020-06-01T10:58:33+00:00\",\"dateModified\":\"2023-12-01T11:05:25+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"A set is an unordered collection of data that cannot store duplicate values, and whose values cannot be changed. On Career Karma, learn how to work with Python sets.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-sets\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-sets\/#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 Sets: A 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 Sets: A Guide | Career Karma","description":"A set is an unordered collection of data that cannot store duplicate values, and whose values cannot be changed. On Career Karma, learn how to work with Python sets.","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-sets\/","og_locale":"en_US","og_type":"article","og_title":"Python Sets: A Guide","og_description":"A set is an unordered collection of data that cannot store duplicate values, and whose values cannot be changed. On Career Karma, learn how to work with Python sets.","og_url":"https:\/\/careerkarma.com\/blog\/python-sets\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-06-01T10:58:33+00:00","article_modified_time":"2023-12-01T11:05:25+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.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-sets\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-sets\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python Sets: A Guide","datePublished":"2020-06-01T10:58:33+00:00","dateModified":"2023-12-01T11:05:25+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-sets\/"},"wordCount":1432,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-sets\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-sets\/","url":"https:\/\/careerkarma.com\/blog\/python-sets\/","name":"Python Sets: A Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg","datePublished":"2020-06-01T10:58:33+00:00","dateModified":"2023-12-01T11:05:25+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"A set is an unordered collection of data that cannot store duplicate values, and whose values cannot be changed. On Career Karma, learn how to work with Python sets.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-sets\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-sets\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-sets\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/woman-sharing-her-presentation-with-her-colleagues-3153198-1.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-sets\/#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 Sets: A 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\/17668","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=17668"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/17668\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/17670"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=17668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=17668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=17668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}