Todd Matsumoto wrote:
Hello,
The other day I needed to pack a dictionary, the value of each key was a list.
In the code I was packing the list and the dictionary at the same time. First I
tried something like this:
list = []
dict = {}
x = 1
dict['int'] = list.append(x)
The result was {'int': None}. Why is the value None?
Cheers,
T
Hi,
Appending to a list does so in-place and returns None. If you wish to
do what you posted you will need to do it in 2 steps with:
list.append(x)
dict['int'] = list
You should also avoid shadowing built-in names like "list", "dict",
"file" etc as you can very easily end up with unexplained errors.
Hope that helps.
--
Kind Regards,
Christian Witts
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor