[Python-Dev] dict.addlist() (original) (raw)
Raymond Hettinger raymond.hettinger at verizon.net
Tue Jan 20 09:17:43 EST 2004
- Previous message: [Python-Dev] Re: isinstance(x, types.UnboundMethodType) feature
- Next message: [Python-Dev] dict.addlist()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Here is anidea to kick around:
Evolve and eventually replace dict.setdefault with a more specialized method that is clearer, cleaner, easier to use, and faster.
d.addlist(k, v) would work like d.setdefault(k, []).append(v)
Raymond Hettinger
d = dict() for elem in 'apple orange ant otter banana asp onyx boa'.split(): ... k = elem[0] ... d.addlist(k, elem) ... d {'a': ['apple', 'ant', 'asp'], 'b': ['banana', 'boa'], 'o': ['orange', 'otter', 'onyx']}
bookindex = dict() for pageno, page in enumerate(pages): for word in page: bookindex.addlist(word, pageno)
- Previous message: [Python-Dev] Re: isinstance(x, types.UnboundMethodType) feature
- Next message: [Python-Dev] dict.addlist()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]