On 9/08/12 23:33:58, Terry Reedy wrote:
> On 8/9/2012 4:06 PM, [email protected] wrote:
[...]
>> unique=dict()
>> for row in array2D :
>> row = tuple(row)
>> if row in unique:
>> unique[row] += 1
>> else:
>> unique[row] = 1
>
> I believe the 4 lines above are equivalent to
> unique[row] = unique.get(row, 0) + 1
I would write that bit as:
from collections import defaultdict
unique = defaultdict(int)
for row in array2D:
unique[row] += 1
Hope this helps,
-- HansM
--
http://mail.python.org/mailman/listinfo/python-list