In Ruby, if I have an array and I want to use both indexes and values ββin a loop, I use each_with_index .
each_with_index
a=['a','b','c'] a.each_with_index{|v,i| puts("#{i} : #{v}") }
prints
0 : a 1 : b 2 : c
What is the python way to do the same?
Sort of:
for i, v in enumerate(a): print "{} : {}".format(i, v)
It will be enumerate .
a=['a','b','c'] for i,v in enumerate(a): print "%i : %s" % (i, v)
Print
Source: https://habr.com/ru/post/1201420/More articles:Is it possible to return multiple values ββfrom mysql function? - functionProvide an optional attribute in the angular ui-router url - angularjsSplit Varchar into a character in MySQL - splitEnvironment variables and artisan not working on production server - phpAngular js - route-ui add default column - javascriptHow to create your own documents locally using devdocs.io - documentationASP.NET Web Application Does Not Unload AppDomains After Deployment - c #Updating Template Error for Underline 1.7 - underscore.jsWhy do I get a "Web Login Required" message when I connect to Gmail via IMAP? - imapDifferences between scala and java values ββ- javaAll Articles