Given a list like this:
mylist = [\"name\", \"state\", \"name\", \"city\", \"name\", \"zip\", \"zip\"]
I would like to rename the duplicate
Less fancy stuff.
from collections import defaultdict
mylist = ["name", "state", "name", "city", "name", "zip", "zip"]
finalList = []
dictCount = defaultdict(int)
anotherDict = defaultdict(int)
for t in mylist:
anotherDict[t] += 1
for m in mylist:
dictCount[m] += 1
if anotherDict[m] > 1:
finalList.append(str(m)+str(dictCount[m]))
else:
finalList.append(m)
print finalList