Last active
February 8, 2023 21:24
-
-
Save yoki/6c528a64f58a1d2d0b881d152d0674a9 to your computer and use it in GitHub Desktop.
List operation/Control sequence/Repeat
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
# 1_loop.py | |
# 2_list_operation.py |
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
for item in items: | |
print(item) | |
if exit_loop_flag: | |
break | |
if go_to_next_loop_flag: | |
continue | |
for ind, val in enumarate(lis): | |
# do something. | |
for key, value in dic.items(): | |
# do something. | |
for key in dic: | |
# do something. | |
for ind, raw in df.iterrows(): | |
# do something | |
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
# list comprehension | |
a_list = [1, ‘4’, 9, ‘a’, 0, 4] | |
squared_ints = [ e**2 for e in a_list if type(e) == types.IntType ] | |
# another way using map and lambda | |
mysq = lambda x: x**2 | |
myfilter = lambda x: type(x) == types.IntType | |
squared_ints = map(mysq, filter(myfilter, a_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment