A query about list

Gerhard Häring gh at ghaering.de
Thu Oct 9 16:17:25 EDT 2003


Santanu Chatterjee wrote:
> Hello everybody,
> 
> I am very new to python. I have a query about 
> list in python.
> 
> Suppose I have a list 
> a = [1,[2,3,4],5,6,7,[8,9,10],11,12]
> I want to know if there is any simple python
> facility available that would expand the above list
> to give
> a = [1,2,3,4,5,6,7,8,9,10,11,12]
> 
> I know I can do that with a type() and a for/while loop,
> but is there any simpler way?

Why do you have such a data structure in the first place? Can't it be 
avoided?

If for example you made the mistake of .append()-ing lists to a list, 
then you can .extend() it instead.

-- Gerhard





More information about the Python-list mailing list