• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Get Python Dictionary Values as List

Get Python Dictionary Values as List

August 19, 2022 Leave a Comment

To get the values of a dictionary in a list in Python, you can use the dictionary values() function and convert it to a list with list().

d = {"a":3, "b": 5, "c":1, "d":2}

list_of_dict_values = list(d.values())

print(list_of_dict_values)

#Output:
[3, 5, 1, 2]

When working with dictionaries, the ability to get information about the keys and values easily can be valuable.

One such case is if you want to get the values of a dictionary and convert the values to a list.

To get the values of a dictionary as a list in Python, you can use the dictionary values() function and convert it to a list with list().

Below shows you how to get dictionary values into a list in Python.

d = {"a":3, "b": 5, "c":1, "d":2}

list_of_dict_values = list(d.values())

print(list_of_dict_values)

#Output:
[3, 5, 1, 2]

Get Keys of Dictionary as List in Python

If you want to get the keys of a dictionary in Python as a list, then you use a similar method as described above.

Instead of using the values() dictionary function, you can use the keys() dictionary function.

keys() returns the keys of a dictionary.

To get the keys of a dictionary as a list in Python, you can use the dictionary keys() function and convert it to a list with list().

Below shows you how to get dictionary keys into a list in Python.

d = {"a":3, "b": 5, "c":1, "d":2}

list_of_dict_keys = list(d.keys())

print(list_of_dict_keys)

#Output:
[3, 5, 1, 2]

Hopefully this article has been useful for you to learn how to get the values of a dictionary into a list using Python.

Other Articles You'll Also Like:

  • 1.  Using Python to Read File Character by Character
  • 2.  Calculate Distance Between Two Points in Python
  • 3.  Length of Dictionary Python – Get Dictionary Length with len() Function
  • 4.  How to Group By Columns and Find Standard Deviation in pandas
  • 5.  How to Cube Numbers in Python
  • 6.  Get First Digit in Number Using Python
  • 7.  Python gethostbyname() Function – Get IPv4 Address from Name
  • 8.  Python Check if List Index Exists Using Python len() Function
  • 9.  Changing Python Turtle Speed with speed() Function
  • 10.  Using Python to Replace Multiple Spaces with One Space in String

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy