Am 12.06.21 um 04:02 schrieb Jach Feng:
def foo():
...     # do something
...
a = []
for i in range(3):
...     a.append(foo())
...
a
[]


How about having "foo" return a list of things? Then you can append that list and return an empty list if you want nothing added:

In [1]: def foo():
   ...:     return [1,2,3]
   ...:

In [2]: def bar():
   ...:     return []
   ...:

In [3]: a=[]

In [4]: a += foo()

In [5]: a
Out[5]: [1, 2, 3]

In [6]: a += bar()

In [7]: a
Out[7]: [1, 2, 3]


        Christian
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to