Python 2.2 dictionary question.

Martin von Loewis loewis at
Mon Jul 23 06:46:39 EDT 2001

Duncan Booth <duncan at> writes:

> In Python 2.2a1 the dictionary type object 'dictionary' in builtins doesn't 
> currently check its arguments at all, so I can call dictionary(1, [66], 
> foo=99) if I really want. I guess that this simply means that the 
> implementation isn't complete, but I wondered what the intention was that 
> dictionary should return. 

Please make a bug report on SF, so this won't be forgotten.

> Something like this perhaps?
>    dictionary() -> {}
>    dictionary({'a': 1, 'b': 2}) -> {'a':1, 'b': 2}
>    dictionary(a=1, b=2) -> {'a': 1, 'b': 2}

This would be an option; the other one would be to disallow arguments
to dictionary. Perhaps following UserDict would be appropriate as
well: dictionary would allow an optional dictionary argument. In fact,
UserDict should be implemented as

UserDict = dictionary

> The other construction that might be useful would be to build a list of 
> (key, value) pairs into a dictionary, reversing the effect of the items() 
> method. This would effectively allow dictionary comprehensions for those 
> that want them:
>    dictionary([(k, v) for k, v in dict if wanted(k)])

Also note that much of this has been discussed before in


More information about the Python-list mailing list