Overriding dict constructor

Raymond Hettinger python at rcn.com
Wed Sep 22 06:38:40 CEST 2010


[Steven D'Aprano]
> But if I try to create a regular dict from this, dict() doesn't call my
> __getitem__ method:
>
> >>> dict(d)
>
> {0: ('a', 'extra_data'), 1: ('b', 'extra_data')}
>
> instead of {0: 'a', 1: 'b'} as I expected.
>
> How can I fix this?

Try using dict(d.items()).


Raymond




More information about the Python-list mailing list