list(...) and list comprehensions (WAS: Arithmetic sequences in Python)

Antoon Pardon apardon at forel.vub.ac.be
Fri Jan 20 06:33:58 EST 2006


Op 2006-01-18, Diez B. Roggisch schreef <deets at nospam.web.de>:
> Giovanni Bajo schrieb:
>> Diez B. Roggisch wrote:
>> 
>>>> due to the nested parentheses.  Note that replacing list comprehensions
>>>> with list(...) doesn't introduce any nested parentheses; it basically
>>>> just replaces brackets with parentheses.
>>> But you don't need the nested parentheses - use *args instead for the
>>> list-constructor.
>>>
>>> list(a,b,c)
>> 
>> No, you can't. That's ambigous if you pass only one argument, and that
>> argument is iterable. This is also the reason why set() doesn't work this
>> way.
>
> Ah, you're right - I thought about the >1 case, but not that one.

Well we could have list(a) return [a], and have a list_from_iterable.
Although I would prefer a different name.

-- 
Antoon Pardon



More information about the Python-list mailing list