Verbose and flexible args and kwargs syntax

Eelco hoogendoorn.eelco at gmail.com
Tue Dec 13 03:30:06 EST 2011


On Dec 13, 1:27 am, alex23 <wuwe... at gmail.com> wrote:
> On Dec 13, 3:12 am, Eelco <hoogendoorn.ee... at gmail.com> wrote:
>
> > But to relate it to the topic of this thread: no, the syntax does not
> > allow one to select the type of the resulting sequence. It always
> > constructs a list.
>
> So by this argument, _every_ function that returns a list should take
> an optional argument to specify an alternative form of sequence.
>
> What, exactly, is so onerous about coercing your list to _whatever_
> type you want? You know, like everybody else has been.
>
> What does this _gain_ you other than one less line of code?

1) Turning two lines of code into a single more readable one is
nothing to scoff at
2) After-the-fact conversion is O(n), getting the view you want right
away is O(1)

Not every function needs this flexibility; many specialized functions
could not care less. But collection unpacking is quite a general
thing, and for the record; slicing a tuple returns a tuple. Would you
rather have that return a list too?



More information about the Python-list mailing list