Skip to content

Instantly share code, notes, and snippets.

@fabsta
Last active January 27, 2020 14:28
Show Gist options
  • Save fabsta/059b91f6e879323af8283de0923f511f to your computer and use it in GitHub Desktop.
Save fabsta/059b91f6e879323af8283de0923f511f to your computer and use it in GitHub Desktop.
[python iterate list] Iterate through a python list #python #pandas
# list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
# 1
# 3
# for index
for i in range(length):
print(list[i])
# 1
# 3
# Using list comprehension
[print(i) for i in list]
# 1
# 3
# # Using enumerate()
for i, val in enumerate(list):
print (i, ",",val)
# 0 , 1
# 1 , 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment