disgrating a list

Diez B. Roggisch deets at nospam.web.de
Sat Sep 2 00:56:28 CEST 2006


jwaixs schrieb:
> 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.

So you're telling us that

if not isinstance(a, list):
    a = [a]
c = a + [b]

is for some reason not desireable, whereas a much more complex (and most 
probably utilizing the very same typechecks) flattening is ok for you?

Not a to convincing argument to me.

Diez



More information about the Python-list mailing list