yoki
8/1/2016 - 12:10 AM

List operation/Control sequence/Repeat

List operation/Control sequence/Repeat

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))