Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to show what is inside variable 'a'?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading