[Python-ideas] A sorted version of **kwargs
MRAB
python at mrabarnett.plus.com
Thu Jan 20 21:28:41 CET 2011
On 20/01/2011 19:47, Tim Delaney wrote:
> On 21 January 2011 06:13, Bruce Leban <bruce at leapyear.org
> <mailto:bruce at leapyear.org>> wrote:
>
> Back to the original problem though: if the issue is that creating
> an ordered dict is clumsy and perhaps interfering with adoption and
> usage then perhaps the notation for ordered dict could be improved.
> Just as we can now use {...} for both dicts and sets, perhaps we
> could add
>
> [ 'b' : 1, 'a' : 2 ]
>
> as a more convenient way of writing
>
> OrderedDict([('b', 1), ('a', 2)])
>
>
> This is parallel to the way that [1,2] is an ordered container while
> {1,2} is unordered.
>
>
> ['b':1] would then be ambiguous (appears to be a slice of a list). More
> obvious in the case of [1:2] ...
>
[snip]
In what way is it ambiguous? [1] isn't ambiguous, is it?
spam[1] is subscripting and [1] is a list; spam[1 : 2] is slicing and
[1 : 2] would be an ordered dict.
More information about the Python-ideas
mailing list