I am going through the exercises of this site https://anandology.com/python-practice-book/working-with-data.html when I tried to recreate the zip function through list comprehension. Now I created this function. But instead of getting a list I get a generator :-(
def zipp (liste1,liste2):
length= len(liste1)
zipped=[]
[zipped.append(tuple(liste1[i], liste2[i]) for i in range(length))]
return zipped
I searched a little in here and found this: Python: why does list comprehension produce a generator?
Accordingly I used the "tuple" statement already but to no awail.
I have no idea why I get a generator even with the tuple() inserted. So my questions:
- why?
- What do I need to change or where can I read/hear more to get "enlightened" myself?
- How could I use the generator to get the result? (or where can I read about this?)
Thanks.
edit: The result I expect is list of tuple with member of each list in it. This I what I should get:
zipp([1, 2, 3], ["a", "b", "c"]) -> [(1, "a"), (2, "b"), (3, "c")]