onlinepersona , 7 days ago Sure you can. As others have said, a list comprehension returns a new list. See the documentation. What are you trying to do though? Append a list comprehension to an existing list? See a modified version of @eager_eagle's code from their comment. def double(x): return 2 * x a = list(range(10)) a.extend(double(value) for value in range(5)) # a has 15 elements print(a) Anti Commercial-AI license
Sure you can. As others have said, a list comprehension returns a new list. See the documentation.
What are you trying to do though? Append a list comprehension to an existing list?
See a modified version of @eager_eagle's code from their comment.
def double(x): return 2 * x a = list(range(10)) a.extend(double(value) for value in range(5)) # a has 15 elements print(a)
Anti Commercial-AI license