Search notes:

Python: enumerate

enumerate(sequence) returns an iterator that provides tuples with two elements: the position of an element in the sequence (that is: the index) and the corresponding value:
someList = ['foo', 'bar', 'baz']

enumeratedList = enumerate(someList)

print (type(enumeratedList))
# <class 'enumerate'>

for index, element in enumeratedList:
    print("{:d}: {:s}".format(index, element) )
# 0: foo
# 1: bar
# 2: baz
Github repository about-python, path: /builtin-functions/enumerate/demo.py

Providing a start value

When using enumerate, the index starts with 0 by default. It is possible to use the optional argument start = n to change the starting index:
things = [ 'foo', 'bar', 'baz' ]

for index, item in enumerate(things, start = 1):
    print(index, item)
#
#  1 foo
#  2 bar
#  3 baz
Github repository about-python, path: /builtin-functions/enumerate/start-value.py

See also

Using enumerate() in a for loop
Python: Built in functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199201, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Python/built-in-functions/enumerate/index(69): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78