Skip to content

Instantly share code, notes, and snippets.

@yoki
Last active February 8, 2023 21:24
Show Gist options
  • Save yoki/6c528a64f58a1d2d0b881d152d0674a9 to your computer and use it in GitHub Desktop.
Save yoki/6c528a64f58a1d2d0b881d152d0674a9 to your computer and use it in GitHub Desktop.
List operation/Control sequence/Repeat
# 1_loop.py
# 2_list_operation.py
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
# 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