Dictionary question.

hawkesed olaamigoquepasa at hotmail.com
Thu Apr 21 20:28:35 EDT 2005


Actually,
  I think I got it now. Here is what I did:
>>> for num in alist:
... 	if adict.has_key(num):
... 		x = adict.get(num)
... 		x = x + 1
... 		adict.update({num:x})
... 	else:
... 		adict.update({num:1})
...
>>> adict
{128: 2, 129: 2, 132: 1, 153: 1, 30: 1, 53: 1, 57: 1, 61: 1, 66: 2, 67:
1, 69: 2, 71: 1, 72: 1, 73: 2, 74: 1, 75: 2, 76: 2, 77: 2, 78: 2, 82:
1, 84: 1, 85: 4, 87: 2, 88: 3, 89: 1, 91: 1, 92: 1, 93: 2, 94: 2, 95:
3, 96: 1, 97: 3, 98: 2, 99: 1, 100: 6, 101: 4, 102: 2, 103: 1, 104: 1,
105: 1, 106: 2, 107: 2, 108: 2, 109: 2, 111: 3, 112: 1, 114: 3, 115: 3,
116: 3, 118: 1, 119: 2, 122: 2, 123: 1, 125: 1, 126: 1}
Thanks all for the help and best regards!
Ed




More information about the Python-list mailing list