disgrating a list

Peter Otten __peter__ at web.de
Fri Sep 1 14:16:44 EDT 2006


jwaixs wrote:

> 
> Diez B. Roggisch wrote:
>> Why do you wrap a in a list? Just
>>
>> c = a + [b]
>>
>> will do it.
> 
> Yes I know, but the problem is I don't know if 'a' is a list or not. I
> could make a type check, but I don't want to program in that way.

Somewhere in the call chain you have made the decision "I want this function
to accept both lists and scalars", but always passing in lists is probably
the better approach. If you want to go with your original idea -- googling
in c.l.py will turn up many more or less optimized variants of flatten()
that basically follow the same approach as yours. There is also
Tkinter._flatten() which you can use though it gives you a tuple, not a
list -- the place at least should meet the "obscurity" criterion :-)

Peter



More information about the Python-list mailing list