Python Map List of Strings to Integer List

后端 未结 9 1308
猫巷女王i
猫巷女王i 2020-12-31 23:05

Let\'s say I have a list

l = [\'michael\',\'michael\',\'alice\',\'carter\']

I want to map it to the following:

k = [1,1,2,3         


        
9条回答
  •  猫巷女王i
    2020-12-31 23:44

    can do it pretty easy without a function :

    j - list()    
    for i in range (len(l)) : 
       j.append((l[i],k[i]))
    

提交回复
热议问题