Skip to content
  • View menu
  • View sidebar

bioinfo core

Index & solution of bioInfo utilities

  • Home
  • All entries
  • Blogs
  • Contact
  • About

Categories

  • Between languages (7)
  • Blogs (8)
  • Python (35)
  • R (1)
  • Unix (37)

Tags

bedfile Blogs conda Excel html numpy Pandas Python R slurm Unix
07/17/202010/21/2021 by bioinfocore

Python dictionary use value to get key

  • Python
  • Python

With value to find the matching key:

# function to return key for any value 
def get_key(my_dict, val): 
    for key, value in my_dict.items(): 
         if val in value: # when your value is a list
         # if val == value: # when your value is a string
             return key 

    return "key doesn't exist"

Source:
https://www.geeksforgeeks.org/python-get-key-from-value-in-dictionary/

Post navigation

← Previous Post Pandas rearrange the order of only two columns
Next Post → Python if any or all True/False in a list
Copyright 2024 | by bioinfocore