Created
October 6, 2022 13:49
-
-
Save kerenskybr/668dfc4c6054c5b9264f40aecef9b4ce to your computer and use it in GitHub Desktop.
Another way to populate a dict when using enumerate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Another way to populate a dict when using enumerate | |
my_dict = {} | |
my_string = 'Something' | |
for i, my_dict[i] in enumerate(my_string): | |
pass | |
# Output: | |
# {0: 'S', 1: 'o', 2: 'm', 3: 'e', 4: 't', 5: 'h', 6: 'i', 7: 'n', 8: 'g'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment