Complex datastructures in Python

Aahz Maruch aahz at netcom.com
Tue Jun 27 17:39:21 EDT 2000


In article <8jb6jr$2uov$1 at news.enteract.com>,
Greg Gallagher  <ggallag at red-bean.com> wrote:
>
>I'm a little disheartened here... I know how to do this in Perl, but I'm
>lost in Python and 
>searching for 'complex data structures' is landing me nowhere. 
>Basically,  I want
>a dictionary whosevalues are lists of dictionaries.  Simple.
>I want to basically loop through some data and so something like this:
>
>while loop:
>   new_forward = {'ip' : ip_address,
>                  'hostname' : hostname,
>                  'mac_address' : mac_address}
>
>   forward[domain].append(new_forward)

Try this:

  if forward.has_key(domain):
    forward[domain].append(new_forward)
  else:
    forward[domain] = [new_forward]
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

The best way to get information on Usenet is not to ask a question,
but to post the wrong information.  --Aahz



More information about the Python-list mailing list