Skip to content

Commit 9af3181

Browse files
✨ std_lib: for-loop index
1 parent e5dfba3 commit 9af3181

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

standard_lib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ A collection of useful snippets using only the standard library.
2828
| file_matching_regex | Find matching files using `re` and `fnmatch` |
2929
| fill_zeros | Fill strings using leading zeros. |
3030
| flatten | Flatten a nested iterable |
31+
| for_loop_index | Utilize enumerate() to get the index of the current iteration |
3132
| function_arguments | Example on how to (not) use function arguments |
3233
| get_password_input | Request user input without showing, what he or she is typing |
3334
| hash_file | Hash a file using built-in packages |

standard_lib/for_loop_index.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
names = ["Sandy", "Florian", "Mike", "Katie", "Maria"]
2+
3+
for i, name in enumerate(names):
4+
print(f"{i+1}. {name}")

0 commit comments

Comments
 (0)