Flattening lists

Tobiah toby at tobiah.org
Thu Feb 5 14:13:20 EST 2009


On Thu, 05 Feb 2009 11:06:39 -0800, Tobiah wrote:

> 
>> Hello everybody,
>> 
>> Any better solution than this?
> 
> a = [1, 2, 3, [4, 5, 6], [[7, 8], [9, 10]]] print str(a).replace('[',
> '').replace(']', '').split(', ')
> 
> ;)

Or:

a = ['text', 'string', 3, [4, 5, 6], [[7, 8], [9, 10]]]
print eval("[" + str(a).replace('[', '').replace(']', '') + "]")

Just tongue in cheek...




More information about the Python-list mailing list