Possible Duplicate:
How do I make a dictionary with multiple keys to one value?
I have 5 columns of data,
usermac, useragent, area ,videoid, number of requests
I want to use both (usermac,useragent) as key to create a dictionary, since unique combination of (usermac, useragent) represents a unique user.
so the dictionary would be like:
usermac1, useragent1: area1, videoid1, 10
area1, videoid2, 29
usermac1, useragent2: area1, videoid1, 90
area1, videoid2, 34
...
I only know how to create a dictionary with only one item as key. so can anyone help?
my code is:
for line in fd_in.readlines():
(mac, useragent, area, videoid, reqs) = line.split()
video_dict = d1.setdefault((mac,useragent) {})
video_dict.setdefault(videoid, []).append(float(reqs))
and it has syntax error:
video_dict = d1.setdefault((mac,useragent) {})