How to efficently build a nested dictionary

Aahz Maruch aahz at panix.com
Sat Mar 10 10:18:03 EST 2001


In article <3AAA2042.E69A53FC at gmx.de>,
Carsten Gaebler  <cgaebler at gmx.de> wrote:
>
>I wrote a script for FTP traffic accounting, i.e. for each "top level"
>FTP directory it counts the bytes transferred per day. The traffic is
>stored in a dictionary that has the following structure:
>
>traffic = {dir: {year: {month: {day: 42}}}}

I think Emile's suggestion to use a single compound key is a good one.
If that's not sufficient *and* you can use Python 2.0, take a look at
the dict.setdefault() method.
-- 
                      --- Aahz (Copyright 2001 by aahz at pobox.com)

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

"Perhaps God rewards martyrs, but life seldom does..." --Ulrika O'Brien



More information about the Python-list mailing list