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
  • 45,835
  • 124
  • 360
  • 647

1 Answers1

2

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

Usernamenotfound
  • 1,351
  • 2
  • 8
  • 16