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 print out the dictionary with for loop? Python

I would like to print the item of dictionary. how to do that?
this is my code

{'naruto': [900, 170], 'onepiece': [600, 60]}

for key, value in stock_dict1.items():
        for value in stock_dict1.values():
            print(key, value[0], value[1])

when I print out, the result will be like this:
how to do that?

naruto      900 170
onepiece    600 60

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 :

Using str.ljust and iterable unpacking:

data = {'naruto': [900, 170], 'onepiece': [600, 60]}

for movie, nums in data.items():
    print(movie.ljust(12, ' '), *nums)

naruto       900 170
onepiece     600 60
    
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