John Nagle schrieb:
> Shaun wrote:
>> I'm trying to create a dictionary with lists as the value for each
>> key.
>
>Try using a tuple, instead of a list, for each key. Tuples
> are immutable, so there's no issue about a key changing while
> being used i
Okay that makes sense. I was assuming that list.append returned the
new list.
thanks
--
http://mail.python.org/mailman/listinfo/python-list
Shaun wrote:
Hi,
I'm trying to create a dictionary with lists as the value for each
key. I was looking for the most elegant way of doing it...
Try using a tuple, instead of a list, for each key. Tuples
are immutable, so there's no issue about a key changing while
being
Shaun wrote:
> testDict = {}
> ...
> testDict [1] = testDict.get (1, []).append ("Test0") # 1 does not
> exist, create empty array
> print testDict
> testDict [1] = testDict.get (1, []).append ("Test1")
> print testDict
>
[ ... ]
> However, the first printout gives {1: None} instead of the desir
Hi,
Shaun wrote:
> I'm trying to create a dictionary with lists as the value for each
> key. I was looking for the most elegant way of doing it...
from collections import defaultdict
d = defaultdict(list)
d["joe"].append("something")
d["joe"].app
Hi,
I'm trying to create a dictionary with lists as the value for each
key. I was looking for the most elegant way of doing it... I thought
this would work:
testDict = {}
...
testDict [1] = testDict.get (1, []).append ("Test0") # 1 does not
exist, create empty array
print testD