On Thursday, April 10, 2014 10:55:10 AM UTC+5:30, balaji marisetti wrote:
> There was long thread discussing flattening of a list on this list :).
> See the link below.

I dont think that thread is relevant to this question:
1. That (started with) a strange/cute way of using names
2. It does not work for heterogenous lists

# One level flatten version
# like the earlier thread without strange naming
# needed by the recursive one below
>>> def fl1(l): return [y for x in l for y in x]


# recursive flatten
>>> def fr(l):
...   if not isinstance(l,list): return [l]
...   return fl1([fr(x) for x in l])


You can replace the list-comps by generator-comps 

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to