serial iteration over several lists

Brandon bmbeck at
Sun Aug 22 08:57:28 CEST 2004

How about this:

>>> import itertools
>>> def mesh_flatten(meshes):
...     return itertools.chain(*meshes)
>>> meshes = [
...     ["face1", "face2", "face3"],
...     ["face4", "face5", "face6"],
...     ["face7", "face8", "face9"],
...     ["face10", "face11", "face12", "face13"],
... ]
>>> list(mesh_flatten(meshes))
['face1', 'face2', 'face3', 'face4', 'face5', 'face6', 'face7',
'face8', 'face9', 'face10', 'face11', 'face12', 'face13']

Martin DeMello <martindemello at> wrote in message news:<tgOVc.176766$gE.1703 at pd7tw3no>...
> Within Blender, I have access to a list of Objects, each Object
> containing a list of Meshes and each Mesh a list of Faces. I'd like to
> implement a face iterator, with both a next() and a prev() method, such
> that if I go off the end of a face list, it goes to the first face in
> the next mesh, similarly for going off the end of the last mesh in an
> object, and similarly for the prev() iterator.
> In other words, I want to simulate appending all the faces into one long
> list, but without the overhead of actually creating the list. I can
> think of several ways to do it, but they all feel like solutions
> 'translated' from some other language - is there a nice pythonic way to
> do this?
> martin

More information about the Python-list mailing list