Python multimap

castironpi castironpi at gmail.com
Wed Aug 27 14:12:37 EDT 2008


On Aug 27, 12:52 pm, brad <byte8b... at gmail.com> wrote:
> Mike Kent wrote:
> > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
> > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >>>> k = {}
> >>>> k['1'] = []
> >>>> k['1'].append('Tom')
> >>>> k['1'].append('Bob')
> >>>> k['1'].append('Joe')
>
> >>>> k['1']
> > ['Tom', 'Bob', 'Joe']
>
> There is only one '1' key in your example. I need multiple keys that are
> all '1'. I thought Python would have something built-in to handle this
> sort of thing.
>
> I need a true multimap:
>
> k['1'] = 'Tom'
> k['1'] = 'Tommy'
>
> without Tommy overwriting Tom and without making K's value a list of
> stuff to append to. That's still just a regular map.

I don't understand what a multimap does that a map of lists doesn't do.



More information about the Python-list mailing list