dictionary wart

Ben Finney bignose-hates-spam at and-benfinney-does-too.id.au
Thu Mar 18 07:52:37 EST 2004


On 18 Mar 2004 04:41:38 -0800, Jesper Olsen wrote:
> Does python have a way of defining a dictionary default? 
> I think not, but are there any plans to incorporate it?
>
> But surprisingly, in python set_default is a dictionary method used
> for looking up a key...

(Probably you mean setdefault(), since there's no set_default attribute
in any default Python object.)

A dict, by design, has a defined set of keys, like all mapping types.
Your "dictionary default" would change a dictionary so that it
effectively had an infinite set of keys.

    <http://www.python.org/doc/current/lib/typesmapping.html>

It sounds like you want an iterator, rather than a dict.

    <http://www.python.org/doc/current/lib/typeiter.html>

But without knowing the problem you're trying to solve, we can only
guess at the solution.

-- 
 \           "I got a postcard from my best friend, it was a satellite |
  `\      picture of the entire Earth. On the back he wrote, 'Wish you |
_o__)                                   were here'."  -- Steven Wright |
Ben Finney <http://bignose.squidly.org/>



More information about the Python-list mailing list