Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:43:50 +03:00
parent ab1ea476c5
commit a5ca5190e5
169 changed files with 0 additions and 626 deletions

View File

@ -0,0 +1,25 @@
---
title: Find keys with value
type: snippet
tags: [dictionary]
cover: laptop-plants-2
dateModified: 2020-11-02T19:27:53+02:00
---
Finds all keys in the provided dictionary that have the given value.
- Use `dictionary.items()`, a generator and `list()` to return all keys that have a value equal to `val`.
```py
def find_keys(dict, val):
return list(key for key, value in dict.items() if value == val)
```
```py
ages = {
'Peter': 10,
'Isabel': 11,
'Anna': 10,
}
find_keys(ages, 10) # [ 'Peter', 'Anna' ]
```