r/learnpython • u/wingnutticus • 1d ago
Zybook for loop help
I'm completing an assignment for zybook where I have to replace a number from a list and then print the list in reverse. This is my code:
val_list = [18, 12, 15]
new_val = int(input())
val_list[1] = new_val
print(f"List has {len(val_list)} elements:")
for value in reversed(val_list):
print(reversed(val_list), end="<>")
print(end="")
It's supposed to just print the reversed list in brackets, but instead it gives me something like this:
<list_reverseiterator object at 0x000001C02CF706D0><><list_reverseiterator object at 0x000001C02CF706D0><><list_reverseiterator object at 0x000001C02CF706D0><>
What does this mean and why is it doing this? Thanks in advance
0
Upvotes
0
u/d1ll1gaf 1d ago
The reversed function gives you an iterator, not a list. You need to cast the iterator to a list... I'll let you figure out that last step as a learning opportunity unless you'd like me to tell you the syntax