{"id":1882,"date":"2018-12-26T12:00:00","date_gmt":"2018-12-26T11:00:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/difference-between-list-tuple-set-and-dictionary-in-python\/"},"modified":"2026-07-05T03:21:59","modified_gmt":"2026-07-05T01:21:59","slug":"difference-between-list-tuple-set-and-dictionary-in-python","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/difference-between-list-tuple-set-and-dictionary-in-python\/","title":{"rendered":"Difference Between List, Tuple, Set and Dictionary in Python"},"content":{"rendered":"<p>We are going to create these various collections data types in Python and also outline the differences between them. <a href=\"#vd\">Find the Video Lesson here<\/a><\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><a href=\"#t1\">Python List<\/a><\/li>\n<li><a href=\"#t2\">Python Tuple<\/a><\/li>\n<li><a href=\"#t3\">Python Dictionary<\/a><\/li>\n<li><a href=\"#t4\">Python Set<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-282 aligncenter\" src=\"https:\/\/www.kindsonthegenius.com\/wp-content\/uploads\/2020\/09\/Differences-between-List-Tuple-Set-and-Dictionary-in-Python-300x147.jpg\" alt=\"\" width=\"290\" height=\"142\" \/><\/p>\n<p><strong id=\"t1\">1. Python List<\/strong><\/p>\n<p>A list in python is a collection of various items\u00a0 which may be either of the same or of different data types.\u00a0 The items in a list are separated by commas and enclosed in square braces. Listing 1.0 shows how to create a list in python<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">assets <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">\"Computer\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Printer\"<\/span>, <span style=\"background-color: #fff0f0;\">\"TV\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Camera\"<\/span>]\r\n\r\nscores <span style=\"color: #333333;\">=<\/span> [<span style=\"color: #0000dd; font-weight: bold;\">56<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">45.9<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">89.5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">70<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">32.9<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">67.4<\/span>]\r\n\r\nletters <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">'k'<\/span>, <span style=\"background-color: #fff0f0;\">'i'<\/span>, <span style=\"background-color: #fff0f0;\">'n'<\/span>, <span style=\"background-color: #fff0f0;\">'d'<\/span>, <span style=\"background-color: #fff0f0;\">'s'<\/span>, <span style=\"background-color: #fff0f0;\">'o'<\/span>, <span style=\"background-color: #fff0f0;\">'n'<\/span>]\r\n\r\nthings <span style=\"color: #333333;\">=<\/span> [<span style=\"background-color: #fff0f0;\">\"chair\"<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">45<\/span>, <span style=\"background-color: #fff0f0;\">'A'<\/span>, <span style=\"background-color: #fff0f0;\">\"house\"<\/span>]\r\n<\/pre>\n<\/div>\n<p>Listing 1.0: Examples of Lists in Python<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t2\">2. Python Tuple<\/strong><\/p>\n<p>A tuple in python is also a collection of items just like list. Take note of the two key difference:<\/p>\n<ul>\n<li>A tuple is immutable (you can&#8217;t change the elements once created)<\/li>\n<li>A tuple is created with rounded braces<\/li>\n<\/ul>\n<p>Listing 1.1 show example of Tuple<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">assets <span style=\"color: #333333;\">=<\/span> (<span style=\"background-color: #fff0f0;\">\"Computer\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Printer\"<\/span>, <span style=\"background-color: #fff0f0;\">\"TV\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Camera\"<\/span>)\r\n\r\nscores <span style=\"color: #333333;\">=<\/span> (<span style=\"color: #0000dd; font-weight: bold;\">56<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">45.9<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">89.5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">70<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">32.9<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">67.4<\/span>)\r\n\r\nletters <span style=\"color: #333333;\">=<\/span> (<span style=\"background-color: #fff0f0;\">'k'<\/span>, <span style=\"background-color: #fff0f0;\">'i'<\/span>, <span style=\"background-color: #fff0f0;\">'n'<\/span>, <span style=\"background-color: #fff0f0;\">'d'<\/span>, <span style=\"background-color: #fff0f0;\">'s'<\/span>, <span style=\"background-color: #fff0f0;\">'o'<\/span>, <span style=\"background-color: #fff0f0;\">'n'<\/span>)\r\n\r\nthings <span style=\"color: #333333;\">=<\/span> (<span style=\"background-color: #fff0f0;\">\"chair\"<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">45<\/span>, <span style=\"background-color: #fff0f0;\">'A'<\/span>, <span style=\"background-color: #fff0f0;\">\"house\"<\/span>)\r\n<\/pre>\n<\/div>\n<p>Listing 1.1: Example of Tuple in Python<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t3\">3. Python Dictionary<\/strong><\/p>\n<p>A dictionary in python is a collections of key-value pairs of item. For each entry, there are two items: a key and a value. Note the following about Python dictionaries<\/p>\n<ul>\n<li>keys in a dictionary must be unique (no two same keys)<\/li>\n<li>keys are immutable<\/li>\n<li>keys and values can be of any data types<\/li>\n<li>the keys() function returns list of keys in a dictionary<\/li>\n<li>the values() function returns list of values in dictionary<\/li>\n<\/ul>\n<p>Example of dictionaries are given in Listing 1.3.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">months <span style=\"color: #333333;\">=<\/span> {\r\n    <span style=\"background-color: #fff0f0;\">\"Jan\"<\/span>: <span style=\"background-color: #fff0f0;\">\"January\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Feb\"<\/span>: <span style=\"background-color: #fff0f0;\">\"Febraury\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Mar\"<\/span>: <span style=\"background-color: #fff0f0;\">\"March\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Apr\"<\/span>: <span style=\"background-color: #fff0f0;\">\"April\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"May\"<\/span>: <span style=\"background-color: #fff0f0;\">\"May\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Jun\"<\/span>: <span style=\"background-color: #fff0f0;\">\"June\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Jul\"<\/span>: <span style=\"background-color: #fff0f0;\">\"July\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Aug\"<\/span>: <span style=\"background-color: #fff0f0;\">\"August\"<\/span>,\r\n    <span style=\"background-color: #fff0f0;\">\"Sep\"<\/span>: <span style=\"background-color: #fff0f0;\">\"September\"<\/span>\r\n}\r\n\r\nweekdays <span style=\"color: #333333;\">=<\/span> {\r\n    <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>: <span style=\"background-color: #fff0f0;\">\"Monday\"<\/span>,\r\n    <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>: <span style=\"background-color: #fff0f0;\">\"Tuesday\"<\/span>,\r\n    <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>: <span style=\"background-color: #fff0f0;\">\"Wednesday\"<\/span>,\r\n    <span style=\"color: #0000dd; font-weight: bold;\">4<\/span>: <span style=\"background-color: #fff0f0;\">\"Thursday\"<\/span>,\r\n    <span style=\"color: #0000dd; font-weight: bold;\">5<\/span>: <span style=\"background-color: #fff0f0;\">\"Friday\"<\/span>,\r\n    <span style=\"color: #0000dd; font-weight: bold;\">6<\/span>: <span style=\"background-color: #fff0f0;\">\"Saturday\"<\/span>,\r\n    <span style=\"color: #0000dd; font-weight: bold;\">7<\/span>: <span style=\"background-color: #fff0f0;\">\"Sunday\"<\/span>\r\n}\r\n<\/pre>\n<\/div>\n<p>Listing 1.2: Examples of Dictionaries in Python<\/p>\n<p>&nbsp;<\/p>\n<p><strong id=\"t4\">4. Python Set<\/strong><\/p>\n<p>A set in python is a collection of items just like Lists and Tuples.\u00a0 Note the following about sets:<\/p>\n<ul>\n<li>A set is created using the set keyword<\/li>\n<li>A set cannot be an element of a set (but a list can be an element of a list)<\/li>\n<\/ul>\n<p><strong><span style=\"color: #ff0000;\">Also note:<\/span> <\/strong>As pointed out by <a id=\"js_1d0\" class=\" UFICommentActorName\" dir=\"ltr\" href=\"https:\/\/www.facebook.com\/lukalittlebigplanet?fref=gc&amp;dti=535001439850941\" target=\"_self\" rel=\"dialog noopener noreferrer\" aria-describedby=\"u_22_1\" aria-owns=\"js_1cy\" data-ft=\"{&quot;tn&quot;:&quot;;&quot;}\" data-hovercard=\"\/ajax\/hovercard\/hovercard.php?id=100000013383501&amp;extragetparams=%7B%22is_public%22%3Afalse%2C%22hc_location%22%3A%22group%22%2C%22directed_target_id%22%3A%22535001439850941%22%7D\">Luka Jeli\u010di\u0107 Lux<\/a>,\u00a0Sets cannot have same element multiple times. Example: When you have set([1,2,2,2,3,3,4,4,5,5]) and print it you get [1,2,3,4,5] as output.<\/p>\n<p>Examples of sets is given in Listing 1.3<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">assets <span style=\"color: #333333;\">=<\/span> set([<span style=\"background-color: #fff0f0;\">\"Computer\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Printer\"<\/span>, <span style=\"background-color: #fff0f0;\">\"TV\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Camera\"])<\/span>\r\n\r\nscores <span style=\"color: #333333;\">=<\/span> set([<span style=\"color: #0000dd; font-weight: bold;\">56<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">45.9<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">89.5<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">70<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">32.9<\/span>, <span style=\"color: #6600ee; font-weight: bold;\">67.4])<\/span>\r\n\r\nletters <span style=\"color: #333333;\">=<\/span> set([<span style=\"background-color: #fff0f0;\">'k'<\/span>, <span style=\"background-color: #fff0f0;\">'i'<\/span>, <span style=\"background-color: #fff0f0;\">'n'<\/span>, <span style=\"background-color: #fff0f0;\">'d'<\/span>, <span style=\"background-color: #fff0f0;\">'s'<\/span>, <span style=\"background-color: #fff0f0;\">'o'<\/span>, <span style=\"background-color: #fff0f0;\">'n'])<\/span>\r\n\r\nthings <span style=\"color: #333333;\">=<\/span> set([<span style=\"background-color: #fff0f0;\">\"chair\"<\/span>, <span style=\"color: #0000dd; font-weight: bold;\">45<\/span>, <span style=\"background-color: #fff0f0;\">'A'<\/span>, <span style=\"background-color: #fff0f0;\">\"house\"])<\/span>\r\n<\/pre>\n<\/div>\n<p style=\"text-align: center;\">Listing 1.3: Example of Set in Python<\/p>\n<p><b id=\"vd\">If you prefer the video lesson<\/b><br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/n0krwG38SHI\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>In the next lesson, we would examine the operations that can be performed on these data types.<br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- MyWebsite1 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-slot=\"6320760377\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- MyWebsite1 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-slot=\"6320760377\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- MyWebsite1 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-slot=\"6320760377\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- MyWebsite1 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-slot=\"6320760377\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- MyWebsite1 --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-7041870931346451\" data-ad-slot=\"6320760377\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We are going to create these various collections data types in Python and also outline the differences between them. Find the Video Lesson here Python &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-1882","post","type-post","status-publish","format-standard","hentry","category-python-tutorials"],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=1882"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1882\/revisions"}],"predecessor-version":[{"id":2050,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/1882\/revisions\/2050"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=1882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=1882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=1882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}