I'm a newbie to python and had a question to ask about vectorizing a code
def makeNames2(nList):
for nLi in nList:
nLIdx=[i for i,j in enumerate(nList) if j==nLi]
if nLIdx.__len__()>1:
for i,j in enumerate(nLIdx):
if i>0: nList[j]=nList[j]+str(i)
return nList
which does the following:
>>> nLTest=['asda','asda','test','ada','test','yuil','test']
>>> print(makenames2(nLTest)
['asda', 'asda1', 'test', 'ada', 'test1', 'yuil', 'test2']
The code works fine, but I was wondering if there is a way to vectorize the for
loops?
EDIT
Thanks everyone for all the three answers. This is exactly what I was interested in and would have liked to selected all answers. I can't select more than one, but all of them work.