{"id":7574,"date":"2025-04-02T07:27:07","date_gmt":"2025-04-02T07:27:07","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7574"},"modified":"2026-02-12T07:04:01","modified_gmt":"2026-02-12T07:04:01","slug":"how-to-compare-two-lists-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/","title":{"rendered":"How to Compare Two Lists in Python"},"content":{"rendered":"\n<p>Python developers commonly use lists to store and manipulate data. Often they need to compare two or more lists to see if they are identical, or they have common elements. There are several easy ways to do this in Python. In this article, we will learn how to compare two lists in Python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#How_to_Compare_Two_Lists_in_Python\" >How to Compare Two Lists in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#1_Using_Set_contructor\" >1. Using Set contructor<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#2_Using_Zip_function\" >2. Using Zip function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#3_Using_List_Comprehension\" >3. Using List Comprehension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#4_Using_itertools\" >4. Using itertools<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#5_Using_for_loop\" >5. Using for loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#6_Using_sort_and_operator\" >6. Using sort and == operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#7_Using_collectionscounter\" >7. Using collections.counter()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Compare_Two_Lists_in_Python\"><\/span>How to Compare Two Lists in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to compare two lists in Python. When we compare two lists, there are many different things that people like to check, depending on their requirement. For example, you may want to see if there are any duplicates, find elements that exist in one list but not the other. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Set_contructor\"><\/span>1. Using Set contructor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The set() constructor converts a list into a set of unique items. Thereafter, you can apply various functions available to the sets to compare lists. These functions are similar to mathematical operations applied to sets. Here is an example to check if two lists have any common elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a=[1, 2, 3, 4]<br>b=[4, 5, 6, 7]<br><br>print(set(a)&amp;set(b)) # output is {4}<br>print(set(a).intersection(b)) # output is {4}<\/pre>\n\n\n\n<p>If you want the result to be a list, then you can wrap the result of above code in list() constructor.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(list(set(a) &amp; set(b))) # output is [4]<\/pre>\n\n\n\n<p>Here is the command to find the union of two lists. This will return the set of union of all elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(set(a).union(b)) # output is {1, 2, 3, 4, 5, 6, 7}<\/pre>\n\n\n\n<p>Similarly, if you want to find the elements that are present in one list but not the other then you can use &#8216;-&#8216; operator to get the difference.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(set(a)-set(b))  # output is {1, 2, 3}<br>print(set(b)-set(a))  # output is {5, 6, 7}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_Zip_function\"><\/span>2. Using Zip function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Zip function accepts two or more iterables such as lists, and zips them together, that is, pairs their 1st items together, then 2nd item together, and so on.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(all(i == j for i, j in zip(a,b)) ) # output is False<\/pre>\n\n\n\n<p>In the above code, we compare the individual items of each pair of items generated using zip() function, for equality. This will return a generator object of boolean values. The All() function will return True, if the result of comparison of each pair of items is True. Else it will return False. Since our lists are not identical, it will return False as the result.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_List_Comprehension\"><\/span>3. Using List Comprehension<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>List comprehensions are useful to quickly loop through one or more lists and evaluate them for a condition. Here is an example to compare two lists using list comprehensions.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print([x for x in a if x in b]) # output is [4]<\/pre>\n\n\n\n<p>In the above code, we loop through list a and in each iteration, we check if the item is also present in list. If so, it is included in the result. Otherwise, it is omitted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_itertools\"><\/span>4. Using itertools<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Itertools is a useful library that contains plenty of useful functions to work with iterable data types. You can use its product() function to obtain a cartesian product of two lists, and store the result in sorted order. We then loop through it to check if any two consecutive items are identical. If so, it is stored in the new list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import itertools<br>c=[]<br>for i in list(itertools.product(a,b)):<br>    if i[0] == i[1]:<br>        c.append(i[0])    <br>print(c) # output is [4]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_for_loop\"><\/span>5. Using for loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you are finding it difficult to understand all these different functions and want a more intuitive solution, then you can go for the good old fashioned for loops. In this method, we loop through one list, and in each iteration we check if each item is present in the other loop, by looping through the other list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">new_list = []<br>for element in a:<br>    if element in b:<br>        new_list.append(element)<br>        <br>print(new_list)   # output is [4]<\/pre>\n\n\n\n<p>One of the advantages of this solution is that you can easily customize it as per your requirement to include\/exclude specific items.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_sort_and_operator\"><\/span>6. Using sort and == operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python lists support sort() function that sorts them. Once they are sorted, you can use equality operator &#8216;==&#8217; to check if they are equal. It will compare the lists item by item, so identical items need to be at the same location. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a=[1, 2, 3, 4]<br>b=[5, 4, 6, 7]<br>a.sort()<br>b.sort()<br>print(a) # output is [1, 2, 3, 4]<br>print(b) # output is [4, 5, 6, 7]<br>if a == b:<br>    print('equal')<br>else: print('not equal')<\/pre>\n\n\n\n<p>Output is &#8216;not equal&#8217;. This method works whether the lists have same number of elements or not.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Using_collectionscounter\"><\/span>7. Using collections.counter()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this solution, we check equality of lists by comparing the frequency of occurrences of its individual items. We will compare the frequency of each item of first list with that of the second. It does not depend on the order of items of the list.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import collections<br>a=[1, 2, 3, 4]<br>b=[5, 4, 6, 7]<br>if(collections.Counter(a)==collections.Counter(b)):<br>    print( \"Equal\")<br>else:<br>    print( \"Non equal\")<\/pre>\n\n\n\n<p>In the above code, we use collections.Counter() function to get frequency of list items. It returns a Counter object such as <em>Counter({1: 1, 2: 1, 3: 1, 4: 1})<\/em>. We use equality operator &#8216;==&#8217; to compare the result of Counter objects for both lists.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several different ways to compare two lists. If your lists are small-medium size, then you can use set() constructor to convert them into set, since it offers many useful functions to compare sets. This may have an overhead for large lists, so you can use list comprehensions in such cases since they are fast. If you need to customize the comparison in a specific way, you can go for the basic nested loop solution mentioned above.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-create-dictionary-from-lists-in-python\/\">How to Create Dictionary from Lists in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-duplicates-from-list-in-python\/\">How to Remove Duplicates in Python List<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-insert-new-column-to-pandas-dataframe\/\">How to Insert New Column to Pandas DataFrame<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.<\/p>\n","protected":false},"author":1,"featured_media":7603,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[403],"class_list":["post-7574","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-compare-lists"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Compare Two Lists in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Compare Two Lists in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-02T07:27:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-12T07:04:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"308\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Compare Two Lists in Python\",\"datePublished\":\"2025-04-02T07:27:07+00:00\",\"dateModified\":\"2026-02-12T07:04:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\"},\"wordCount\":815,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1\",\"keywords\":[\"compare lists\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\",\"name\":\"How to Compare Two Lists in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1\",\"datePublished\":\"2025-04-02T07:27:07+00:00\",\"dateModified\":\"2026-02-12T07:04:01+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1\",\"width\":308,\"height\":204,\"caption\":\"compare two lists in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Compare Two Lists in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Compare Two Lists in Python - Ubiq BI","description":"Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.","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:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Compare Two Lists in Python - Ubiq BI","og_description":"Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-04-02T07:27:07+00:00","article_modified_time":"2026-02-12T07:04:01+00:00","og_image":[{"width":308,"height":204,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Compare Two Lists in Python","datePublished":"2025-04-02T07:27:07+00:00","dateModified":"2026-02-12T07:04:01+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/"},"wordCount":815,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1","keywords":["compare lists"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/","name":"How to Compare Two Lists in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1","datePublished":"2025-04-02T07:27:07+00:00","dateModified":"2026-02-12T07:04:01+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes Python developers need to compare two lists in Python. Here are the different ways to compare lists in Python.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1","width":308,"height":204,"caption":"compare two lists in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-compare-two-lists-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Compare Two Lists in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/compare-two-lists-in-python.jpg?fit=308%2C204&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1Ya","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7574"}],"version-history":[{"count":30,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7574\/revisions"}],"predecessor-version":[{"id":10590,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7574\/revisions\/10590"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7603"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}