Friday 27 September 2013

condensing the code or a one liner possible for this code in python

condensing the code or a one liner possible for this code in python

I have the following code and wondering if there is a simpler way to do
this. I am creating a list of tuples that holds letters from a string and
the corresponding number from a list. here it is
s="hello"
lst=[1,2,3,4,5]
res = []
for i in range(len(lst)):
res.append((s[i],lst[i]))
print res
The output is here which is correct. I am looking for condensed version if
possible
[('h', 1), ('e', 2), ('l', 3), ('l', 4), ('o', 5)]

No comments:

Post a Comment