d = {1: 'hello', 2: 'goodbye'}
d2 = {True: "somestring", False: ""}
if d2.pop(False):
x = d.pop(1)
else:
x = d.pop(2)
x
?d2
?def map2(function, arguments):
result_list = []
for arg in arguments:
result_list.append(function(arg))
return result_list
def square(n):
return n * n
map2(square, [1, 2, 3, 4, 5])
def strange_loop(l):
out = []
for item in l:
if item is None: # `item is None` evaluates to True when item contains None
return out
out.append(item)
return out
strange_loop([1, 2, 5, 9, None, 3, 1, 1, None])
Requirements:
https://goo.gl/H0vV4x
Comments & Docstrings