Вот старомодный способ:
Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import generators
>>> def mychain(iterables):
... for it in iterables:
... for item in it:
... yield item
...
>>> x = iter([ xrange(0,5), xrange(5,10)])
>>> a = mychain(x)
>>> list(a)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
Я не уверен, какова цель или польза от использования iter()
, в данном случае:
>>> x = [xrange(0,5), xrange(5,10)]
>>> a = mychain(x)
>>> list(a)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>