2011/3/24 Rafael Durán Castañeda <rafadurancastan...@gmail.com>: > I can do it with two list comprehensions: > >>>> list_ = [1, 2, [3, 4], 5, [6, 7, 8], 9] >>>> [x[i] for x in list_ if isinstance(x, list) for i in range(len(x))] + [x >>>> for x in list_ if not isinstance(x, list)] > [3, 4, 6, 7, 8, 1, 2, 5, 9] >>>> > > But i loose original order, Can anyone do it with just one list > comprehension and/or keeping the order?
A more important problem is that it is flattening only one level. Multi-level flattening is I think not possible without using some kind of recursion. -- André Engels, andreeng...@gmail.com _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor