|
Stefan Schwarzer |
at Oct 24, 2010 at 6:58 pm
|
⇧ |
| |
Hi Sebastian,
On 2010-10-21 00:27, Sebastian wrote:
Is there a simpler way to yield all elements of a sequence than this?
for x in xs:
yield x
Can you give an example where you would need this? Can't
you just iterate over the sequence? If you really need an
iterator, you can use `iter(sequence)`:
my_list = [1, 2, 3]
i = iter(my_list)
i.next()
1
2
3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
This works at least with Python's built-in sequences (and
dictionaries and sets, but note that these don't have an
obvious order).
Stefan