problem with dictionaries within lists
Alex Martelli
aleax at aleax.it
Wed Sep 25 05:11:14 EDT 2002
Grant Hallam wrote:
...
> However, the list seems to get populated with the same dictionary
...
> webdatabaselist.append(dict)
Of course -- you ARE appending the same dict over ands over (AFAICT --
you're probably using tabs for indentation, making your code hard to
comprehend for those who read news with KDE's KNode [or MS's OE] as
tabs don't show there... use spaces, NOT tabs...).
Anyway, you probably need something like:
webdatabaselist.append(dict.copy())
dict = {}
either might suffice, but generally you'll need to copy the
current dict AND make dict empty for the next leg of the loop,
if I get the general drift. If you do rebind name dict to {} for
the next leg, then you don't need the call to the copy method.
Alex
More information about the Python-list
mailing list