Python Forum
Help! zip() function - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help! zip() function (/thread-26946.html)



Help! zip() function - bwdu - May-19-2020

Hello everyone!
I couldn't understand why it didn't write y. How can i fix this ---> <zip object at 0x0139F608> ?
Here is my code:
rbooks = []
nratings = []
books = list(a)
for i in range(13):
    c = random.choice(books)
    print(c)
    rbooks.append(c)
    
    m = input("rate: ")
    nratings.append(m)

print(rbooks)

print(nratings)

y = zip(rbooks,nratings)
print(y)
Output:
['Elizabeth Laird,Kiss the Dust\n', 'Elizabeth Laird,Kiss the Dust\n', 'Guy Gavriel Kay,The Summer Tree\n', 'Dan Brown,The Da Vinci Code\n', 'H G Wells,The War Of The Worlds\n', 'Lurlene McDaniel,Breathless\n', 'Patricia C. Wrede,Dealing with Dragons\n', 'Suzanne Collins,The Hunger Games\n', 'C S Lewis,The Lion the Witch and the Wardrobe\n', 'Meg Cabot,The Princess Diaries\n', "Douglas Adams,The Hitchhiker's Guide To The Galaxy\n", 'Meg Cabot,The Princess Diaries\n', 'Maya Angelou,I Know Why the Caged Bird Sings\n'] ['5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5'] <zip object at 0x0139F608>



RE: Help! zip() function - ndc85430 - May-19-2020

See the discussion in this thread - it's the same thing.


RE: Help! zip() function - Larz60+ - May-19-2020

replace line 17 with
for item in y:
...     print(item)
Also, using one letter names is taboo, you should make it a habit to use meaningful names, even with throwaway scripts.