Tricky Dictionary Question from newbie

Bengt Richter bokr at oz.net
Tue Jul 12 14:47:55 EDT 2005


On Tue, 12 Jul 2005 11:52:41 -0400, Tim Peters <tim.peters at gmail.com> wrote:

>[Peter Hansen]
>...
>> I suppose I shouldn't blame setdefault() itself for being poorly named,
>
>No, you should blame Guido for that <wink>.
>
>> but it's confusing to me each time I see it in the above, because the
>> name doesn't emphasize that the value is being returned, and yet that
>> fact is arguably more important than the fact that a default is set!
>>
>> I can't think of a better name, though, although I might find "foo" less
>> confusing in the above context. :-)
>
>I wanted to call it getorset() -- so much so that even now I sometimes
>still type that instead!  The "get" part reminds me that it's fetching
>a value, same as dict.get(key, default) -- "or set"'ing it too if
>there's not already a value to "get".  If you have a fancy enough
>editor, you can teach it to replace setdefault by getorset whenever
>you type the former ;-)

But it isn't get OR set, it's
set_default_if_no_value_then_either_way_effectively_get ;-)
Regards,
Bengt Richter



More information about the Python-list mailing list