Python multimap

Mike Kent mrmakent at cox.net
Wed Aug 27 09:52:23 EDT 2008


On Aug 27, 9:35 am, brad <byte8b... at gmail.com> wrote:
> Recently had a need to us a multimap container in C++. I now need to
> write equivalent Python code. How does Python handle this?
>
> k['1'] = 'Tom'
> k['1'] = 'Bob'
> k['1'] = 'Joe'
> ...
>
> Same key, but different values. No overwrites either.... They all must
> be inserted into the container
>
> Thanks,
> Brad

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']
>>>



More information about the Python-list mailing list