how to show what is inside variable 'a'?

Viewed 44
sizes=[5,12,18,23,42]
a=zip(sizes[:-1],sizes[1:])
print(a)

the result is this


<zip object at 0x0000018607996D80>

Process finished with exit code 0

2 Answers

You probably want to use the following:

print(list(a))
# [(5, 12), (12, 18), (18, 23), (23, 42)]

you are currently printing a zip object, which is printing as expected. Casting it to a list let's you view the entire thing.

More Details

zip works lazily, so it only actually processes the elements as you ask to see them. As a result, there isn't really anything to show. Converting to a list processes all of the elements and stores them in a list.

here is if you need a list like output

sizes=[5,12,18,23,42]
sizes[1:]
a=zip(sizes[:-1],sizes[1:])
print(list(a))
Related