Tuple assignment and generators?

Ant antroy at gmail.com
Thu May 4 18:36:20 CEST 2006


I don't think he was explicitly wanting to initialize things to zero,
but rather unpack an arbitrary sequence into a tuple (could perhaps be
the fibonnacci sequence for example).

How about:

>>> def zeros(count):
...     for i in range(count):
...         yield 0
...
>>> a,b,c = zeros(3)
>>> a
0
>>> b
0
>>> c
0




More information about the Python-list mailing list