I need an explanation about the functioning of Python related to this specific case: I have a list comprehension that calls a function for every element of the listA
. With this code:
listA = [1,1,1]
def operation(n):
result = []
*code do something*
result = [a,b,c]
return result
listB = [operation(element) for element in listA]
I obtain:
listB = [[a,b,c],[a,b,c],[a,b,c]]
How can I return multiple element of a list individually so as to achieve this?
listB = [a,b,c,a,b,c,a,b,c]
What I tried is:
ListA = [1,1,1]
def operation(n):
result = []
*code do something*
result = [a,b,c]
for x in result:
return x
Output: [a,a,a]
instead of [a,b,c,a,b,c,a,b,c]
Note1: cannot use any import
Note2: I put a simplistic case and I cannot transform the list in flat list, what I would need is to be able to return multiple values from a single call, is it possible? Thank you