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

Experimenting with nested tuples.: Why is this saying it's got too many variables?

I’m reading about nested tuples at the moment and trying a very simple one. Can someone point out to where I’m going wrong?

albums = ("Backstreet Boys", "1991", 
          [("No place"), ("Backstreet's Back"), ("Everybody")])

for artist,year,songs in albums:
    print("Artist: {}\nYear:{}\nSongs: {}".format((artist,year,songs)))

Thanks for the help, everyone. 🙂

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 need to wrap the albums tuple in a list and remove the brackets in the format command.

albums = [("Backstreet Boys", "1991", 
          [("No place"), ("Backstreet's Back"), ("Everybody")])]

for artist,year,songs in albums:
    print("Artist: {}\nYear:{}\nSongs: {}".format(artist,year,songs))

That is because xou try to iterate through the tuple albums, not a list of tuples.

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