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
Post a Comment