Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! zip() function
#1
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>
Reply
#2
See the discussion in this thread - it's the same thing.
Reply
#3
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020