I have some headache with this python code.
print "length:", len(pub) # length: 420pub_dict = dict((p.key, p) for p in pub)print "dict:", len(pub_dict) # length: 163
If I understand this right, I get a dictionary containing the attribute p.key
as key and the object p
as its value for each element of pub
. Are there some side effect I don't see? Because len(pub_dict)
should be the same as len(pub)
and it is certainly not here, or am I mistaken?