Using information from a while loop to print a dictionary

I have written a simple program that asks for an artist and album title from a loop:


I can create the loop and a dictionary but I don’t know how to turn the ouput into a dictionary.

Can anyone help please?


If you create a blank dictionary: dict = {}
… you can then use dict[key] = value

If the key is already in said dictionary, the current value will be updated with a new value, else a new kay:value pair will be created.

Thanks Rob, I’ll try that

No worries. If you get stuck, post back with your code (formatted code, rather than a SS) and I’m sure that I, or anther member, will be able to help.

To add: sorry, I’ve just realized what I’ve done, that is not good to do : dict = {} ← Don’t do that, because dict is a reserved word, so use something else, such as album_info = {}, or whatever makes for a good name.

Thanks Rob.

Can you tell me how to format my code using Markdown so I don’t have to use screen grabs please?


No worries: there is a button that you may be able to see, at the top of the edit window – </> which you could use; I don’t. I simply wrap any code in a format block (which does the same thing).

Your format block should look like this, before you post:

# this is where you code block will go; between the and bottom
# this next line, etc, like this, as an example:

for x in range(10):

Maybe I should say that the marks are called backtics, usually found top left of a keyboard, just below the Esc key.

Backtics that’s it. I have done that before but I couldn’t for the life of me remember. Thankyou

You’re welcome.

This may be of help:

Thanks Rob

1 Like