Haskell: How to convert a list to a list where each element is a tuple of its location in the list and the original data? -


this question has answer here:

i need convert list list each element tuple of location in list , original data.such

[a,b,c,d] -> [(1,a),(2,b),(3,c),(4,d)] 

the easiest method can conceive of using zip function. takes 2 lists arguments , returns list of tuples. pair range [1..] , have desire:

zip [1..] [a,b,c,d] 

will return

[(1,a),(2,b),(3,c),(4,d)] 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -