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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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