What is the pythonic way of appending returned variables (More than of one) from a function to different lists?
Suppose we got a function like:
def func():
return np.random.randint(0, 10), np.random.randint(10, 20)
The simplest non pythonic way to do it is:
l1 = []
l2 = []
for i in range(x):
# do something
# do something else
a, b = func()
l1.append(a)
l2.append(b)
Or using numpy:
lst = []
for i in range(x):
# do something
# do something else
lst.append(func())
l1, l2 = np.array(lst).T
Or extracting items using solutions provided here.