Is there a way to get the following result in Python?

Peter Otten __peter__ at web.de
Tue Jun 15 02:47:41 EDT 2021


On 12/06/2021 04:02, Jach Feng wrote:

>>>> def foo():
> ...     # do something
> ...
>>>> a = []
>>>> for i in range(3):
> ...     a.append(foo())
> ...
>>>> a
> []

The most natural way to achieve something similar is to replace append() 
with extend():

 >>> def foo(): return ()

 >>> a = []
 >>> for i in range(3):
	a.extend(foo())

	
 >>> a
[]





More information about the Python-list mailing list