HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

How to get a key from a value in Python

42,049 views October 25, 2018 1:38

Watch on YouTube
ChannelEnthought

Description from the creator

In this short tutorial, you will learn how to find which key (or keys) is associated with a value in a dictionary in Python using a list comprehension. Want to learn more? See our Python classes at goo.gl/xQf9P3.

Read the documentation for list comprehensions here: docs.python.org/3/tutorial/datastructures.html#…

Code from video:
*****************
employees = {1: 'michael', 2: 'eric', 3: 'michael'}
[number for number, name in employees.items() if name == 'michael']

Connect with us!
*****************
twitter.com/enthought
facebook.com/Enthought/
linkedin.com/company/enthought

About this tutorial

Enthought published this 1:38 video tutorial on October 25, 2018. It has been watched 42,049 times on YouTube.

Channel
Enthought
Duration
1:38
Published
October 25, 2018
Views
42,049
Likes
263

Tags

Share

Further reading

  • How to Extract Key from Python Dictionary using Value | by ... towardsdatascience.com

    Four methods to extract keys from python dictionary given value. Abhijith Chandradas. Nov 7 · 3 min read. It is straight-forward to extract value if we have key, like unlocking a lock with a key. However, the vice versa…

  • Python | Get key from value in Dictionary - GeeksforGeeks geeksforgeeks.org

    Let’s see how to get the key by value in Python Dictionary. Method #1: Using list.index() The index() method returns index of corresponding value in a list. . Below is an implementation how to use index() method to fetc…

  • Get key from value in Dictionary in Python tutorialspoint.com

    Python dictionary contains key value pairs. In this article we aim to get the value of the key when we know the value of the element. Ideally the values extract ...

This tutorial in other languages