[Python-ideas] change list() - branch from "More useful slices"

Ethan Furman ethan at stoneleaf.us
Tue Feb 3 01:55:15 CET 2015


On 02/02/2015 04:40 PM, Alexander Heger wrote:
>>> Well, if something useful comes out of this discussion, maybe it would
>>> be an idea to extend list to allow the former syntax naively assumed,
>>>
>>> list('foo', 'bar', 'baz')
>>
>> I see no point to this versus ['foo', 'bar', 'baz']
>>
>>> similar to what exists for dict():
>>>
>>> dict(a=1, b=2, c=3)
> 
> The point is that makes it easier for people to remember if they can
> do it in a similar way.
> (same would be for tuple()).  This way you could have pragmatic
> verbose forms for all three, the only point of confusion being if
> there is only one argument, which is iterable, the behaviour will be
> different, i.e., the current default behaviour.
> 
> If a single non-iterable item gives a list as well, that could be
> nice, but makes the outcome dependent on the type of the object.  A
> concern could be that the result is less easy to predict when just
> reading code.  But so are many things.

The one-item case will be a bug-magnet, and outweigh the benefits of not typing [] or ().  That is a bad trade.

--
~Ethan~

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150202/e25cfe7b/attachment.sig>


More information about the Python-ideas mailing list