A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2000-August/007887.html below:

A small proposed change to dictionaries' "get" method

[Python-Dev] Re: A small proposed change to dictionaries' "get" methodSkip Montanaro skip@mojam.com (Skip Montanaro)
Thu, 3 Aug 2000 17:21:04 -0500 (CDT)
    >> How about making this a method:

    >> def inplace(dict, key, default):

    >>     value = dict.get(key, default)
    >>     dict[key] = value
    >>     return value

eh... I don't like these do two things at once kind of methods.  I see
nothing wrong with

    >>> dict = {}
    >>> dict['hello'] = dict.get('hello', [])
    >>> dict['hello'].append('world')
    >>> print dict
    {'hello': ['world']}

or

    >>> d = dict['hello'] = dict.get('hello', [])
    >>> d.insert(0, 'cruel')
    >>> print dict
    {'hello': ['cruel', 'world']}

for the obsessively efficiency-minded folks.

Also, we're talking about a method that would generally only be useful when
dictionaries have values which were mutable objects.  Irregardless of how
useful instances and lists are, I still find that my predominant day-to-day
use of dictionaries is with strings as keys and values.  Perhaps that's just
the nature of my work.

In short, I don't think anything needs to be changed.

-1 (don't like the concept, so I don't care about the implementation)

Skip



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4