{"id":21722,"date":"2022-04-04T16:04:36","date_gmt":"2022-04-04T10:34:36","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=21722"},"modified":"2022-04-04T16:04:44","modified_gmt":"2022-04-04T10:34:44","slug":"python-foreach","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-foreach\/","title":{"rendered":"Do You Need A Foreach in Python? [Alternatives]"},"content":{"rendered":"\n<p>Java 5 introduced the foreach method for iterating arrays similarly to the for loop, <span style=\"text-decoration: underline;\"><strong><a href=\"http:\/\/www.pythonpool.com\/for-vs-while-loop-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">while loop<\/a><\/strong><\/span>, and do-while loop. Unfortunately, there is no exact foreach keyword in Python. There are different ways through which you can use it.<\/p>\n\n\n\n<p>Like a normal for-loop, it begins with the keyword for. Rather than declaring and initializing loop counter variables, you declare a variable with the same type as the array, followed by a colon and then the array name. You can use your loop variable instead of an indexed array element in the loop body. <\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">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: #990303;color:#990303\" 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: #990303;color:#990303\" 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 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Whats_the_Difference_between_For_and_Foreach_Loop\" >What&#8217;s the Difference between For and Foreach Loop?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Is_there_a_foreach_looping_statement_in_Python\" >Is there a foreach looping statement in Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Writing_a_User_Defined_Foreach_loop_in_Python\" >Writing a User Defined Foreach loop  in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Writing_a_Traditional_For_Loop_in_Python\" >Writing a Traditional For Loop in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Iterating_Through_a_Dictionary_in_Python_using_foreach\" >Iterating Through a Dictionary in Python using foreach<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Parallelizing_the_for_loop_In_Python\" >Parallelizing the for loop In Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Foreach_Loops_Using_Django_Templates\" >Foreach Loops Using Django Templates<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Skipping_the_First_or_Last_Element_Using_Python_For_Loop\" >Skipping the First or Last Element  Using Python For Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#FAQs_on_Python_Foreach\" >FAQs on Python Foreach<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#Trending_Python_Articles\" >Trending Python Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-s-the-difference-between-for-and-foreach-loop\"><span class=\"ez-toc-section\" id=\"Whats_the_Difference_between_For_and_Foreach_Loop\"><\/span>What&#8217;s the Difference between For and Foreach Loop?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>For Loop<\/th><th>Foreach Loop<\/th><\/tr><\/thead><tbody><tr><td>The most traditional way of iterating over arrays<\/td><td>A modern approach to iterating over sequence data types.<\/td><\/tr><tr><td>It does not pass any call-back functions while iterating.<\/td><td>The foreach loop passes a call-back function for each element of an array.<\/td><\/tr><tr><td>Works with an iterator, counter, and incrementor.<\/td><td>Works with the iterator, index of an element, and sequence type to iterate through.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-is-there-a-foreach-looping-statement-in-python\"><span class=\"ez-toc-section\" id=\"Is_there_a_foreach_looping_statement_in_Python\"><\/span>Is there a foreach looping statement in Python?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>As of Python 3.10, there isn&#8217;t a dedicated foreach syntax available. The standard Python for loop has similar functionality to a so-called &#8220;foreach loop&#8221;. Look at the below example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfor item in sequence:\n     print(item)\n<\/pre><\/div>\n\n\n<p>The above <span style=\"text-decoration: underline;\"><strong><a href=\"http:\/\/www.pythonpool.com\/python-iterate-through-list\/\" target=\"_blank\" rel=\"noreferrer noopener\">loop iterates through each &#8220;item&#8221;<\/a><\/strong><\/span> in the sequence structure. On every iteration, the loop performs a print operation on the &#8220;item&#8221;. This, as you can see, is very similar to a Foreach statement in Java. A call-back, in this case &#8211; print, is being requested.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-writing-a-user-defined-foreach-loop-in-python\"><span class=\"ez-toc-section\" id=\"Writing_a_User_Defined_Foreach_loop_in_Python\"><\/span>Writing a User Defined Foreach loop  in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The following example shows how a standard foreach loop works. You can try this implementation on your browser <a href=\"http:\/\/www.pythonpool.com\/python-compiler\/\">here<\/a>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\ndef myForEach(aFunction, anIterable):\n    for eachElement in anIterable:\n        aFunction(eachElement)\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\" id=\"h-explanation\">Explanation:<\/h4>\n\n\n\n<p><code>myForEach<\/code> Is a function that takes 2 arguments. One is a function to allow call-backs for each <code>eachElement<\/code>. The other is a sequence data or an iterable type. Upon each iteration, a call back is performed  <code>aFunction<\/code> on each item in the iterable. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-writing-a-traditional-for-loop-in-python\"><span class=\"ez-toc-section\" id=\"Writing_a_Traditional_For_Loop_in_Python\"><\/span>Writing a Traditional For Loop in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The example below illustrates how traditional for-loops work.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmyArray = &#x5B;'a', 'b', 'c']\nfor index in range(len(myArray)):\n    print(&quot;index: %s | value: %s&quot; % (index, myArray&#x5B;index]))\n<\/pre><\/div>\n\n\n<p id=\"h-output\"><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">index: 0 | value: a\nindex: 1 | value: b\nindex: 2 | value: c<\/pre>\n\n\n\n<p id=\"block-27ad8cc0-e565-4e9f-974e-79eec5404c3a\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<p id=\"block-27ad8cc0-e565-4e9f-974e-79eec5404c3a\">We iterate through the array myArray consisting of 3 elements in our &#8220;for loop&#8221;. Instead of iterating through the array itself, we&#8217;re keeping track of the index values. The iterations proceed till the end of the array. Unlike the foreach loop, the for loop iterates based on the size of the iterable and keeps track of the index position.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-iterating-through-a-dictionary-in-python-using-foreach\"><span class=\"ez-toc-section\" id=\"Iterating_Through_a_Dictionary_in_Python_using_foreach\"><\/span>Iterating Through a Dictionary in Python using foreach<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For dictionaries and mappings, <code><strong>__iter()<\/strong>__<\/code> is used to iterate over keys. In other words, if you directly put a dictionary into a for loop, Python will automatically call <code>__<strong>iter<\/strong>()__<\/code>  on that dictionary, giving you an iterator over its keys.<\/p>\n\n\n\n<p>Python understands that a_dict is a dictionary and that it implements <code>__<strong>iter<\/strong>()__<\/code>.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nmyDict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}\nfor key in myDict:\n     print(key)\n<\/pre><\/div>\n\n\n<p>Upon each iteration, the loop is making a call-back to the &#8220;print&#8221; function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parallelizing-the-for-loop-in-python\"><span class=\"ez-toc-section\" id=\"Parallelizing_the_for_loop_In_Python\"><\/span>Parallelizing the for loop In Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Using Python&#8217;s multiprocessing package, we can send a request to another process and create a child process, parallelizing the loop. For each element of the iterable, the multiprocessing module could be substituted for the for loop. Due to the Global <a href=\"https:\/\/en.wikipedia.org\/wiki\/Interpreter_(computing)\" target=\"_blank\" rel=\"noreferrer noopener\">Interpreter<\/a> Lock, using multiple threads in Python would not provide better results<code>. multiprocessing.pool()<\/code> function can be used. Refer to the following implementation:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport multiprocessing\n\ndef sumAll(value):\n    return sum(range(1, value + 1))\n\npool_obj = multiprocessing.Pool()\n\nresult = pool_obj.map(sumAll,range(0,5))\nprint(result)\n<\/pre><\/div>\n\n\n<p id=\"h-output\"><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0, 1, 3, 6, 10<\/pre>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-kilo monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-foreach-loops-using-django-templates\"><span class=\"ez-toc-section\" id=\"Foreach_Loops_Using_Django_Templates\"><\/span>Foreach Loops Using Django Templates<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>A Django template is a text document or a Python string mark-up using the Django template language. These templates allow data from viewable to the template and provide features of programming such as variables, loops, and comments.<\/p>\n\n\n\n<p>Here&#8217;s the Django template syntax for a for loop.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{% for i in iterable %}\n{% endfor %}<\/pre>\n\n\n\n<p>Actual implementation:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&lt;ul&gt;\n{% for Item in MyDict %}\n    &lt;li&gt;{{ MyDict.value}}&lt;\/li&gt;\n{% endfor %}\n&lt;\/ul&gt;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-skipping-the-first-or-last-element-using-python-for-loop\"><span class=\"ez-toc-section\" id=\"Skipping_the_First_or_Last_Element_Using_Python_For_Loop\"><\/span>Skipping the First or Last Element  Using Python For Loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To skip the first element in an iterable, pass:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfor item in myIterable&#x5B;1:]:\n     print(item)\n<\/pre><\/div>\n\n\n<p>Similarly, to skip the last element:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfor item in myIterable&#x5B;:-1]:\n     print(item)\n<\/pre><\/div>\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-golf monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\">[Fixed] nameerror: name Unicode is not defined<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs-on-python-foreach\"><span class=\"ez-toc-section\" id=\"FAQs_on_Python_Foreach\"><\/span>FAQs on Python Foreach<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1648555313350\"><strong class=\"schema-faq-question\">How is Python Foreach better than the standard for loop?<\/strong> <p class=\"schema-faq-answer\">foreach loops are usually faster\u00a0because the local variable that stores the element&#8217;s value in the array is faster to access than an element in the array. However, the for loop can be more efficient if the iterable has to be accessed every iteration.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1648585545220\"><strong class=\"schema-faq-question\">Why Python doesn&#8217;t require foreach?<\/strong> <p class=\"schema-faq-answer\">As discussed, Python&#8217;s for-loop has behaviors similar to a standard foreach loop. Python for loop iterates through each &#8220;item&#8221; in the sequence structure. On every iteration, the loop performs a print operation on the &#8220;item&#8221;. Thereby functioning similarly to a traditional foreach.<\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We have discussed the foreach loop and its relevancy in Python 3. The differences between the classic for and for each loop have been established. We have also discussed how the Python for loop behaves like a foreach loop in functionality.<\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-delta monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-2\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Python_Articles\"><\/span>Trending Python Articles<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 11, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined.webp 1200w \" alt=\"[Fixed] nameerror: name Unicode is not defined\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal.webp 1200w \" alt=\"[Solved] runtimeerror: cuda error: invalid device ordinal\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method.webp 1200w \" alt=\"[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>Java 5 introduced the foreach method for iterating arrays similarly to the for loop, while loop, and do-while loop. Unfortunately, there is no exact foreach &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Do You Need A Foreach in Python? [Alternatives]\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/#more-21722\" aria-label=\"More on Do You Need A Foreach in Python? [Alternatives]\">Read more<\/a><\/p>\n","protected":false},"author":28,"featured_media":22419,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[5107,5106,5108,5109,5110,5105,5104],"class_list":["post-21722","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-questions","tag-python-foreach-array","tag-python-foreach-dictionary","tag-python-foreach-file-in-directory","tag-python-foreach-lambda","tag-python-foreach-line-in-file","tag-python-foreach-list","tag-python-foreach-loop","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Do You Need A Foreach in Python? [Alternatives] - Python Pool<\/title>\n<meta name=\"description\" content=\"Like a normal for-loop, Python Foreach with the keyword for. Rather than declaring and initializing loop counter variables.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-foreach\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Do You Need A Foreach in Python? [Alternatives]\" \/>\n<meta property=\"og:description\" content=\"Java 5 introduced the foreach method for iterating arrays similarly to the for loop, while loop, and do-while loop. Unfortunately, there is no exact\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-foreach\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-04T10:34:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-04T10:34:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Vishnu Venkatesh\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishnu Venkatesh\" \/>\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:\/\/www.pythonpool.com\/python-foreach\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/\"},\"author\":{\"name\":\"Vishnu Venkatesh\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/5e8aa48e7557450d345c829305550688\"},\"headline\":\"Do You Need A Foreach in Python? [Alternatives]\",\"datePublished\":\"2022-04-04T10:34:36+00:00\",\"dateModified\":\"2022-04-04T10:34:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/\"},\"wordCount\":758,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp\",\"keywords\":[\"python foreach array\",\"python foreach dictionary\",\"python foreach file in directory\",\"python foreach lambda\",\"python foreach line in file\",\"python foreach list\",\"python foreach loop\"],\"articleSection\":[\"Questions\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-foreach\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-foreach\/\",\"name\":\"Do You Need A Foreach in Python? [Alternatives] - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp\",\"datePublished\":\"2022-04-04T10:34:36+00:00\",\"dateModified\":\"2022-04-04T10:34:44+00:00\",\"description\":\"Like a normal for-loop, Python Foreach with the keyword for. Rather than declaring and initializing loop counter variables.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648555313350\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648585545220\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-foreach\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp\",\"width\":1200,\"height\":628,\"caption\":\"Python Foreach\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Do You Need A Foreach in Python? [Alternatives]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/5e8aa48e7557450d345c829305550688\",\"name\":\"Vishnu Venkatesh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8d399a4488a19871b08a11ebd884e233b04c76d12edc4c7278a79d69df853d75?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8d399a4488a19871b08a11ebd884e233b04c76d12edc4c7278a79d69df853d75?s=96&d=wavatar&r=g\",\"caption\":\"Vishnu Venkatesh\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648555313350\",\"position\":1,\"url\":\"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648555313350\",\"name\":\"How is Python Foreach better than the standard for loop?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"foreach loops are usually faster\u00a0because the local variable that stores the element's value in the array is faster to access than an element in the array. However, the for loop can be more efficient if the iterable has to be accessed every iteration.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648585545220\",\"position\":2,\"url\":\"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648585545220\",\"name\":\"Why Python doesn't require foreach?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"As discussed, Python's for-loop has behaviors similar to a standard foreach loop. Python for loop iterates through each \\\"item\\\" in the sequence structure. On every iteration, the loop performs a print operation on the \\\"item\\\". Thereby functioning similarly to a traditional foreach.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Do You Need A Foreach in Python? [Alternatives] - Python Pool","description":"Like a normal for-loop, Python Foreach with the keyword for. Rather than declaring and initializing loop counter variables.","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:\/\/www.pythonpool.com\/python-foreach\/","og_locale":"en_US","og_type":"article","og_title":"Do You Need A Foreach in Python? [Alternatives]","og_description":"Java 5 introduced the foreach method for iterating arrays similarly to the for loop, while loop, and do-while loop. Unfortunately, there is no exact","og_url":"https:\/\/www.pythonpool.com\/python-foreach\/","og_site_name":"Python Pool","article_published_time":"2022-04-04T10:34:36+00:00","article_modified_time":"2022-04-04T10:34:44+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp","type":"image\/webp"}],"author":"Vishnu Venkatesh","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Vishnu Venkatesh","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-foreach\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/"},"author":{"name":"Vishnu Venkatesh","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/5e8aa48e7557450d345c829305550688"},"headline":"Do You Need A Foreach in Python? [Alternatives]","datePublished":"2022-04-04T10:34:36+00:00","dateModified":"2022-04-04T10:34:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/"},"wordCount":758,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp","keywords":["python foreach array","python foreach dictionary","python foreach file in directory","python foreach lambda","python foreach line in file","python foreach list","python foreach loop"],"articleSection":["Questions"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-foreach\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.pythonpool.com\/python-foreach\/","url":"https:\/\/www.pythonpool.com\/python-foreach\/","name":"Do You Need A Foreach in Python? [Alternatives] - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp","datePublished":"2022-04-04T10:34:36+00:00","dateModified":"2022-04-04T10:34:44+00:00","description":"Like a normal for-loop, Python Foreach with the keyword for. Rather than declaring and initializing loop counter variables.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648555313350"},{"@id":"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648585545220"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-foreach\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-foreach\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/04\/Python-Foreach.webp","width":1200,"height":628,"caption":"Python Foreach"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-foreach\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Do You Need A Foreach in Python? [Alternatives]"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/5e8aa48e7557450d345c829305550688","name":"Vishnu Venkatesh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8d399a4488a19871b08a11ebd884e233b04c76d12edc4c7278a79d69df853d75?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8d399a4488a19871b08a11ebd884e233b04c76d12edc4c7278a79d69df853d75?s=96&d=wavatar&r=g","caption":"Vishnu Venkatesh"}},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648555313350","position":1,"url":"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648555313350","name":"How is Python Foreach better than the standard for loop?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"foreach loops are usually faster\u00a0because the local variable that stores the element's value in the array is faster to access than an element in the array. However, the for loop can be more efficient if the iterable has to be accessed every iteration.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648585545220","position":2,"url":"https:\/\/www.pythonpool.com\/python-foreach\/#faq-question-1648585545220","name":"Why Python doesn't require foreach?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"As discussed, Python's for-loop has behaviors similar to a standard foreach loop. Python for loop iterates through each \"item\" in the sequence structure. On every iteration, the loop performs a print operation on the \"item\". Thereby functioning similarly to a traditional foreach.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/21722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=21722"}],"version-history":[{"count":45,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/21722\/revisions"}],"predecessor-version":[{"id":22422,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/21722\/revisions\/22422"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/22419"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=21722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=21722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=21722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}