Re: Python multimap

2008-08-28 Thread Carl Banks
On Aug 28, 2:41 pm, brad <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > Out of curiosity, what does a true multimap solve that a dictionary of > > lists not solve? > > Nothing really. I went with a variation of the suggested work around... > it's just that with Python I don't normally have to u

Re: Python multimap

2008-08-28 Thread brad
Carl Banks wrote: Out of curiosity, what does a true multimap solve that a dictionary of lists not solve? Nothing really. I went with a variation of the suggested work around... it's just that with Python I don't normally have to use work arounds and normally one obvious approach is correct:

Re: Python multimap

2008-08-27 Thread Carl Banks
On Aug 27, 1:52 pm, brad <[EMAIL PROTECTED]> 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'].app

Re: Python multimap

2008-08-27 Thread castironpi
On Aug 27, 1:38 pm, brad <[EMAIL PROTECTED]> wrote: > castironpi wrote: > > I don't understand what a multimap does that a map of lists doesn't do. > > It counts both keys individually as separate keys. The Python workaround > does not... see examples... notice the key(s) that are '4' > > Python ou

Re: Python multimap

2008-08-27 Thread Fredrik Lundh
Miles wrote: That's what a multimap is. iirc, a C++ multimap provides a flat view of the data, so you need to provide custom enumeration and iteration methods as well. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python multimap

2008-08-27 Thread brad
castironpi wrote: I don't understand what a multimap does that a map of lists doesn't do. It counts both keys individually as separate keys. The Python workaround does not... see examples... notice the key(s) that are '4' Python output (using the k = [] idea): Key: 4 Value: [[13, 'Visa'],

Re: Python multimap

2008-08-27 Thread castironpi
On Aug 27, 12:52 pm, brad <[EMAIL PROTECTED]> 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'].ap

Re: Python multimap

2008-08-27 Thread Miles
brad wrote: > 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 ... without making K's value a list of stuff > to append to. That's what a multimap is. If yo

Re: Python multimap

2008-08-27 Thread brad
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']

Re: Python multimap

2008-08-27 Thread Michele Petrazzo
brad 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

Re: Python multimap

2008-08-27 Thread Matt Nordhoff
brad 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

Re: Python multimap

2008-08-27 Thread Mike Kent
On Aug 27, 9:35 am, brad <[EMAIL PROTECTED]> 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