1

I'm generating an index value associated with each tuple value :

a = ["what" , "a" , "test"]

c = 0
d = []
for b in a : 
    d.append((c , b))
    c = c + 1

print(d)

generates :

[(0, 'what'), (1, 'a'), (2, 'test')]

Is there Python idiomatic / functional way to implement same functionality ?

Something like :

list(map(lambda x : (x , c+1) , a))
blue-sky
  • 51,962
  • 152
  • 427
  • 752

1 Answers1

2

list(enumerate(a)) should give you what you want

usernamenotfound
  • 1,540
  • 2
  • 11
  • 18