from dictionary to list comprehension

i want to know do we able to create dictionary into list via list comprehension… and in

n_list=[letter for letter in name]

what actually these “letters” define… what the core idea…


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @Sky01,

Basically, you want to create a list from a dictionary, is that correct? Now, do you want to merge all keys and values of your dictionary into a list or create two separate lists, one for your keys and one for your values?

Let’s say you want to create one list containing both the key and values of your dictionary:

for key, value in dict.iteritems():
    temp = [key,value]

If you want to create different lists for both your key and your value, you can try :

# Create a list of keys

# Create a list of values

Regards, KFSys