{"id":807,"date":"2022-06-28T21:48:00","date_gmt":"2022-06-28T16:18:00","guid":{"rendered":"https:\/\/geekpython.in\/?p=807"},"modified":"2023-08-15T16:50:42","modified_gmt":"2023-08-15T11:20:42","slug":"zip-function-in-python-usage-and-examples-with-code","status":"publish","type":"post","link":"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code","title":{"rendered":"zip() Function In Python &#8211; Usage &amp; Examples With Code"},"content":{"rendered":"\n<p><strong><em>Have you ever heard the word &#8220;parallel iteration&#8221; or tried to &#8220;loop over multiple iterables in parallel&#8221; when you were coding in Python?<\/em><\/strong><\/p>\n\n\n\n<p>This tutorial will show a Python&nbsp;<code>zip()<\/code>&nbsp;function that helps us perform a&nbsp;<strong>parallel iteration over multiple iterables<\/strong>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-definition\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-definition\"><\/a>Definition<\/h1>\n\n\n\n<p>The <code>zip()<\/code>&nbsp;function takes iterables and iterates over them parallelly, which results in producing tuples of each item from the iterables.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">items = [\"Computer\", \"Keyboard\", \"CPU\", \"Mouse\"]\nunits = [3, 2, 4, 6]\n\nmapping = zip(items, units)\n\nprint(tuple(mapping))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">(('Computer', 3), ('Keyboard', 2), ('CPU', 4), ('Mouse', 6))<\/pre><\/div>\n\n\n\n<p>In other words, it returns the&nbsp;<strong>iterator of tuples<\/strong>&nbsp;where the&nbsp;<strong>first item in each passed iterator is paired together<\/strong>&nbsp;and then the&nbsp;<strong>second item in each passed iterator is paired together<\/strong>&nbsp;and it&nbsp;<strong>goes so on until the shortest iterator is exhausted<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Another way to think of&nbsp;<code>zip()<\/code>&nbsp;is that it turns rows into columns and columns into rows. This is similar to transposing a matrix.<a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/functions.html#zip\" rel=\"noreferrer noopener\">Source<\/a><\/p>\n<\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-syntax\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-syntax\"><\/a>Syntax<\/h1>\n\n\n\n<p>The syntax of Python&nbsp;<code>zip()<\/code>&nbsp;function is:<\/p>\n\n\n\n<p><code>zip(*iterables)<\/code>&nbsp;or&nbsp;<code>zip(iterator1, iterator2, ...)<\/code><\/p>\n\n\n\n<p><strong>In Python 3.10, the<\/strong>&nbsp;<code>strict<\/code>&nbsp;<strong>argument was added<\/strong><\/p>\n\n\n\n<p><code>zip(*iterables, strict=False)<\/code><\/p>\n\n\n\n<p>We&#8217;ll see the use of&nbsp;<code>strict<\/code>&nbsp;ahead in this tutorial.<\/p>\n\n\n\n<p><code>zip()<\/code>&nbsp;<strong>parameters:<\/strong><\/p>\n\n\n\n<p><code>iterables<\/code>: they can be lists, tuples, dictionaries, or objects that can be iterated.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-example\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-example\"><\/a>Example<\/h1>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">languages = [\"Python\", \"JavaScript\", \"C\", \"C++\"]\nfounded = [1991, 1995, 1972, 1985]\n\nmapping = zip(languages, founded)\n\nprint(list(mapping))\n\nprint(type(list(mapping)))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">[('Python', 1991), ('JavaScript', 1995), ('C', 1972), ('C++', 1985)]\n&lt;class 'list'&gt;<\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-working-of-zip-function\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-working-of-zip-function\"><\/a>Working of zip() function<\/h1>\n\n\n\n<p>How&nbsp;<code>zip()<\/code>&nbsp;function creates an iterator of the tuple?<\/p>\n\n\n\n<p>We can actually say that zipping means aggregating two separate things into one.<\/p>\n\n\n\n<p>Just like it, the&nbsp;<strong>Python<\/strong>&nbsp;<code>zip()<\/code>&nbsp;<strong>function works by taking two inputs say<\/strong>&nbsp;<code>A1<\/code>&nbsp;<strong>and<\/strong>&nbsp;<code>A2<\/code>,&nbsp;<strong>and then aggregating the item of the same index number of<\/strong>&nbsp;<code>A1<\/code>&nbsp;<strong>and<\/strong>&nbsp;<code>A2<\/code>.<\/p>\n\n\n\n<p>We will better understand through the illustration below<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"1000\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/zipfuncworking.png\" alt=\"zip function working\" class=\"wp-image-808\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We can clearly see, on the right side &#8211; the tuple at the 0th index contains each item of&nbsp;<code>A1<\/code>&nbsp;and&nbsp;<code>A2<\/code>&nbsp;at the 0th index respectively.<\/li>\n\n\n\n<li>The same goes for items at the 1st index of&nbsp;<code>A1<\/code>&nbsp;and&nbsp;<code>A2<\/code>.<\/li>\n\n\n\n<li>In general, the tuple at the index&nbsp;<code>i<\/code>&nbsp;contains items at the index&nbsp;<code>i<\/code>&nbsp;in&nbsp;<code>A1<\/code>&nbsp;and&nbsp;<code>A2<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong><em>More formally: zip() returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument iterables.<\/em><\/strong><a target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/functions.html#zip\" rel=\"noreferrer noopener\"><strong><em>Source<\/em><\/strong><\/a><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-iterables-of-different-lengths\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-iterables-of-different-lengths\"><\/a>Iterables of different lengths<\/h1>\n\n\n\n<p>What happens if iterables are of different lengths?<\/p>\n\n\n\n<p>Nothing&#8217;s gonna happen if the iterables passed to the&nbsp;<code>zip()<\/code>&nbsp;function have different lengths because&nbsp;<strong>if we refer to official Python docs then it states that&nbsp;<em>&#8220;the iterator stops when the shortest iterable is exhausted&#8221;<\/em>.<\/strong><\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">languages = [\"Python\", \"JavaScript\", \"C\", \"C++\"]\nfounded = [1991, 1995, 1972]\n\nmapping = zip(languages, founded)\n\nprint(list(mapping))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">[('Python', 1991), ('JavaScript', 1995), ('C', 1972)]<\/pre><\/div>\n\n\n\n<p>Here, the&nbsp;<code>C++<\/code>&nbsp;was excluded because the&nbsp;<code>founded<\/code>&nbsp;variable contains only three arguments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"heading-what-if-python-throws-an-error-when-the-iterables-are-of-different-lengths\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-what-if-python-throws-an-error-when-the-iterables-are-of-different-lengths\"><\/a>What if Python throws an error when the iterables are of different lengths?<\/h3>\n\n\n\n<p>Let&#8217;s understand with an example<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">languages = [\"Python\", \"JavaScript\", \"C\", \"C++\"]\nfounded = [1991, 1995, 1972]\n\nmapping = zip(languages, founded, strict=True)\n\nprint(list(mapping))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Traceback (most recent call last):\n  ....\nValueError: zip() argument 2 is shorter than argument 1<\/pre><\/div>\n\n\n\n<p>Did you notice that there is an additional argument&nbsp;<code>strict=True<\/code>&nbsp;in the code?<\/p>\n\n\n\n<p>The&nbsp;<code>strict<\/code>&nbsp;argument is added in&nbsp;<strong>Python version 3.10<\/strong><\/p>\n\n\n\n<p>If the iterables have different lengths and we use the&nbsp;<code>strict<\/code>&nbsp;argument, the code will throw a&nbsp;<code>ValueError<\/code>. It can be useful for debugging.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-passing-one-or-no-iterable-to-the-zip\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-passing-one-or-no-iterable-to-the-zip\"><\/a>Passing one or no iterable to the zip()<\/h1>\n\n\n\n<p><strong>The<\/strong>&nbsp;<code>zip()<\/code>&nbsp;<strong>function will return an empty iterator if no parameters were passed<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">no_iterable = zip()\nprint(list(no_iterable))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">[]<\/pre><\/div>\n\n\n\n<p><strong>If we pass only one iterable, then the<\/strong>&nbsp;<code>zip()<\/code>&nbsp;<strong>function will return an iterator of tuples each having only one element.<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">languages = [\"Python\", \"JavaScript\", \"C\", \"C++\"]\n\nmapping = zip(languages)\n\nprint(list(mapping))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">[('Python',), ('JavaScript',), ('C',), ('C++',)]<\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-python-zip-examples\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-python-zip-examples\"><\/a>Python zip() Examples<\/h1>\n\n\n\n<p><strong>Example: Using<\/strong>&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/geekpython.in\/python-enumerate-function-with-example-beginner-s-guide\" target=\"_blank\"><strong><code>enumerate()<\/code><\/strong><\/a>&nbsp;<strong>function with <code>zip()<\/code><\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\n\nresult = zip(characters, real_names)\n\nfor num, results in enumerate(result):\n    print(num, results)<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">0 ('Iron Man', 'RDJ')\n1 ('Thor', 'Chris Hemsworth')\n2 ('Spiderman', 'Andrew Garfield')<\/pre><\/div>\n\n\n\n<p><strong>Example: Using <code>range()<\/code> function<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">name = [\"Sachin\", \"Rishu\", \"Yashwant\", \"Abhishek\"]\n\nvalues = zip(range(4), name)\n\nprint(tuple(values))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">((0, 'Sachin'), (1, 'Rishu'), (2, 'Yashwant'), (3, 'Abhishek'))<\/pre><\/div>\n\n\n\n<p><strong>Example: Having multiple iterables<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\nreel_names = [\"Tony Stark\", \"Thor\", \"Peter Parker\"]\n\nresult = zip(characters, real_names, reel_names)\n\nprint(list(result))<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">[('Iron Man', 'RDJ', 'Tony Stark'), ('Thor', 'Chris Hemsworth', 'Thor'), ('Spiderman', 'Andrew Garfield', 'Peter Parker')]<\/pre><\/div>\n\n\n\n<p><strong>Example: Typecasting into different data types<\/strong><\/p>\n\n\n\n<p><strong>Typecasting into List<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\n\nresult = zip(characters, real_names)\n\nprint(f\"List: {list(result)} and type is {type(list(result))}\")<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">List: [('Iron Man', 'RDJ'), ('Thor', 'Chris Hemsworth'), ('Spiderman', 'Andrew Garfield')] and type is &lt;class 'list'&gt;<\/pre><\/div>\n\n\n\n<p><strong>Typecasting into Dictionary<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\n\nresult = zip(characters, real_names)\n\nprint(f\"Dictionary: {dict(result)} and type is {type(dict(result))}\")<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Dictionary: {'Iron Man': 'RDJ', 'Thor': 'Chris Hemsworth', 'Spiderman': 'Andrew Garfield'} and type is &lt;class 'dict'&gt;<\/pre><\/div>\n\n\n\n<p><strong>Typecasting into Set<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\n\nresult = zip(characters, real_names)\n\nprint(f\"Set: {set(result)} and type is {type(set(result))}\")<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Set: {('Iron Man', 'RDJ'), ('Spiderman', 'Andrew Garfield'), ('Thor', 'Chris Hemsworth')} and type is &lt;class 'set'&gt;<\/pre><\/div>\n\n\n\n<p><strong>Typecasting into Tuple<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\n\nresult = zip(characters, real_names)\n\nprint(f\"Tuple: {tuple(result)} and type is {type(tuple(result))}\")<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Tuple: (('Iron Man', 'RDJ'), ('Thor', 'Chris Hemsworth'), ('Spiderman', 'Andrew Garfield')) and type is &lt;class 'tuple'&gt;<\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-unzipping-the-values\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-unzipping-the-values\"><\/a>Unzipping the Values<\/h1>\n\n\n\n<p>We can actually&nbsp;<strong>unzip the values<\/strong>&nbsp;that were&nbsp;<strong>already zipped<\/strong>. Let&#8217;s see how to do so.<\/p>\n\n\n\n<p>This can be done with the help of&nbsp;<code>*<\/code>&nbsp;<a target=\"_blank\" href=\"https:\/\/geekpython.in\/asterisk-in-python\" rel=\"noreferrer noopener\">asterisk operator<\/a>.<\/p>\n\n\n\n<p>Let&#8217;s understand with an example.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">characters = [\"Iron Man\", \"Thor\", \"Spiderman\"]\nreal_names = [\"RDJ\", \"Chris Hemsworth\", \"Andrew Garfield\"]\nreel_names = [\"Tony Stark\", \"Thor\", \"Peter Parker\"]\n\nmapping = zip(characters, real_names, reel_names)\n\nmapped = list(mapping)\n\nprint(f\"Zipped result: {mapped}\", end=\"\")\n\nprint(\"\\n\")\n\n# unzipping values\nchar, real, reel = zip(*mapped)\n\nprint(\"Unzipped result:\")\n\nprint(f\"The characters list is : {char}\")\n\nprint(f\"The real_names list is : {real}\")\n\nprint(f\"The reel_names list is : {reel}\")<\/pre><\/div>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">Zipped result: [('Iron Man', 'RDJ', 'Tony Stark'), ('Thor', 'Chris Hemsworth', 'Thor'), ('Spiderman', 'Andrew Garfield', 'Peter Parker')]\n\nUnzipped result:\nThe characters list is : ('Iron Man', 'Thor', 'Spiderman')\nThe real_names list is : ('RDJ', 'Chris Hemsworth', 'Andrew Garfield')\nThe reel_names list is : ('Tony Stark', 'Thor', 'Peter Parker')<\/pre><\/div>\n\n\n\n<p>Notice how we unzipped the values of the variable&nbsp;<code>mapped<\/code>&nbsp;using&nbsp;<code>*<\/code>&nbsp;and to store the unzipped values we declared three variables&nbsp;<code>char<\/code>,&nbsp;<code>real<\/code>&nbsp;and&nbsp;<code>reel<\/code><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-conclusion\"><a href=\"https:\/\/geekpython.in\/zip-function-in-python-usage-and-examples-with-code#heading-conclusion\"><\/a>Conclusion<\/h1>\n\n\n\n<p>In this tutorial, you&#8217;ve learned to perform a parallel iteration using Python&#8217;s&nbsp;<code>zip()<\/code>&nbsp;function and I hope you understand how to use it.<\/p>\n\n\n\n<p>You now understand how the&nbsp;<code>zip()<\/code>&nbsp;function works behind the scenes to generate a tuple iterator.<\/p>\n\n\n\n<p>Try the code snippets written above in your IDEs to understand the code better.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83c\udfc6<strong>Other articles you might be interested in if you liked this one<\/strong><\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/convert-bytes-into-string\" rel=\"noreferrer noopener\">How to convert bytes into strings in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/f-string-in-python\" rel=\"noreferrer noopener\">f-string: An improved and modern way of string formatting<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/access-list-values-within-the-dictionary\" rel=\"noreferrer noopener\">How to access the list values within the dictionary in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/str-and-repr-in-python\" rel=\"noreferrer noopener\">How to use __str__ and __repr__ to change the string representation of the objects in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/python-sort-vs-sorted\" rel=\"noreferrer noopener\">How do sort() and sorted() functions are different from each other<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/seek-and-tell-in-python\" rel=\"noreferrer noopener\">What is the difference between seek() and tell() in Python<\/a>?<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/tempfile-in-python\" rel=\"noreferrer noopener\">How to use tempfile module to create temporary files and dirs in Python<\/a>?<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>That&#8217;s all for now.<\/strong><\/p>\n\n\n\n<p><strong>Keep Coding\u270c\u270c<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever heard the word &#8220;parallel iteration&#8221; or tried to &#8220;loop over multiple iterables in parallel&#8221; when you were coding in Python? This tutorial will show a Python&nbsp;zip()&nbsp;function that helps us perform a&nbsp;parallel iteration over multiple iterables. Definition The zip()&nbsp;function takes iterables and iterates over them parallelly, which results in producing tuples of each [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":810,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[2,41],"tags":[40,12,31],"class_list":["post-807","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-function","tag-functions","tag-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/comments?post=807"}],"version-history":[{"count":2,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/807\/revisions"}],"predecessor-version":[{"id":1373,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/807\/revisions\/1373"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/810"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}