{"id":6965,"date":"2020-11-24T13:17:06","date_gmt":"2020-11-24T07:47:06","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=6965"},"modified":"2020-11-24T13:18:19","modified_gmt":"2020-11-24T07:48:19","slug":"enumerate-in-python-with-examples","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/enumerate-in-python-with-examples\/","title":{"rendered":"Enumerate in Python with EXAMPLES"},"content":{"rendered":"\n<p>Sometimes you want to reference your items in the list or other data structure for later use. It makes easier by providing an enumerate function in <a href=\"https:\/\/www.h2kinfosys.com\/blog\/what-is-new-in-python-programming\/\">Python<\/a>.\u00a0<\/p>\n\n\n\n<p>Let&#8217;s take a look at the parameter of enumerate.<\/p>\n\n\n\n<p>enumerate(iterable, startIndex)<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Iterable<\/strong>: list or other iterable.<\/li><li><strong>StartIndex<\/strong>: It is the starting number. StartIndex is optional.<\/li><\/ul>\n\n\n\n<p>Let\u2019s take a look at the code.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>name = [&#8216;Alex&#8217;, &#8216;Bob&#8217; ,&#8217;Celvin&#8217;, &#8216;Dexter&#8217;]<br>e_name = enumerate(name)<br>print(e_name)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/Kxmk_D_SDqwIundhYk7N7WdQBlgN4uwOe8pV_dMKcWcTXJ39KUJkmSyC6xifI-DB7pwylw-9076ZQEJmfM56C84oK8qSzxsFr9WRP63WpA2AV5djw5Z_Oh8d8QvdbEbGSkQmSKiAL64abgVSwQ\" alt=\"Enumerate in Python\" title=\"\"><\/figure>\n\n\n\n<p>The enumerate function returns an enumerate object that we need to iterate to get the output values. Let us <a href=\"https:\/\/www.w3schools.com\/python\/python_iterators.asp#:~:text=An%20iterator%20is%20an%20object%20that%20can%20be%20iterated%20upon,)%20and%20__next__()%20.\" rel=\"nofollow noopener\" target=\"_blank\">iterate <\/a>through the list.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>name = [&#8216;Alex&#8217;, &#8216;Bob&#8217; ,&#8217;Celvin&#8217;, &#8216;Dexter&#8217;]<br>e_name = enumerate(name)<br>for i in e_name:<br>print(i)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/jjJBhVfnAB-h6gp7O18xq9npA7ASbyofialbZUutK-X_O46oXpOfUh4bJl9Mknd_QGs6KN-9UrIXj3LWVzff-APDf8GaQjjLqLj5q298GH9MxQt-YbZMokSv29e_STPEmZClKKwiTmozUlYChg\" alt=\"Enumerate in Python\" title=\"\"><\/figure>\n\n\n\n<p>Now let\u2019s start counting from 5 now.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>name = [&#8216;Alex&#8217;, &#8216;Bob&#8217; ,&#8217;Celvin&#8217;, &#8216;Dexter&#8217;]<br>e_name = enumerate(name,5)<br>for i in e_name:<br>&nbsp; print(i)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The following is the output<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/QHyo9qP9Pfeb0VlYF8uQS9CHryLZmu2zdeFBdvRcpK5F2JNW2hA8MPkmImemcZvxblX_2cDhkbouwIVFngFRPW-Umu9_ci5tvF7B9xr-hxKHIaHJeHdGdHROoMmZnizUQ1lQ_aChMFAhu-jjOw\" alt=\"Enumerate in Python\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Enumerating a Tuple<\/h2>\n\n\n\n<p>The enumerate on tuple works the same as on lists.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>name = (&#8216;Alex&#8217;, &#8216;Bob&#8217; ,&#8217;Celvin&#8217;, &#8216;Dexter&#8217;)<br>e_name = enumerate(name)<br>for i in e_name:<br>print(i)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/LEt-VSUCGLxImFgCluBqKI3Xu65gWMKyBUFrNkTuCFAcB0c6sjjFmPh0V6NFnclU0qmpexK2a3sj9783f1Lf7o_Gi8ZbyPus2bbOK3-LLYQcf2ZdTKRggz8X2Xh7tY7c8i5OfTwPivGIBsYCNA\" alt=\"Enumerating a Tuple\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Enumerating a String<\/h2>\n\n\n\n<p>Let\u2019s take a look at the code to enumerate in python string.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>name = (&#8216;Hello&#8217;)<br>e_name = enumerate(name)<br>for i in e_name:<br>print(i)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/JcpWYObcX4NjlJz3hd-JDMpnSFW1yMQsvpQ10Av7Zugd1XeexyAfSSS_Hu4Sr1Fr4FwhHtol3OVoE8Zg_FKBFmJ4-oOo3PvNUQWBzY0cLi79Yf-QLrP1QUKT1KTELBYHtb5Yli3HkuBdl05qLg\" alt=\"Enumerating a String\" title=\"\"><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you want to reference your items in the list or other data structure for later use. It makes easier by providing an enumerate function in Python.\u00a0 Let&#8217;s take a look at the parameter of enumerate. enumerate(iterable, startIndex) Iterable: list or other iterable. StartIndex: It is the starting number. StartIndex is optional. Let\u2019s take a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7006,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[342],"tags":[],"class_list":["post-6965","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=6965"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6965\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/7006"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=6965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=6965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=6965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}