This is my first python program -
Requirement: Read a file consisting of {adId UserId} in each line. For each adId, print the number of unique userIds.
Here is my code, put together from reading the python docs. Could you give me feedback on how I can write this in more python-ish way?
CODE :
import csv
adDict = {}
reader = csv.reader(open("some.csv"), delimiter=' ')
for row in reader:
adId = row[0]
userId = row[1]
if ( adId in adDict ):
adDict[adId].add(userId)
else:
adDict[adId] = set(userId)
for key, value in adDict.items():
print (key, ',' , len(value))
Thanks.