Answers for "find number of dictionaries in a list python"

2

python find dict in list of dict by id

>>> dicts = [
     { "name": "Tom", "age": 10 },
     { "name": "Mark", "age": 5 },
     { "name": "Pam", "age": 7 },
     { "name": "Dick", "age": 12 }
 ]
>>> next(item for item in dicts if item["name"] == "Pam")
{'age': 7, 'name': 'Pam'}

# WITH DEFAULT VALUE TO None if None
next((item for item in dicts if item["name"] == "pam"), None)
Posted by: Guest on March-10-2021
1

get number of key in dictionary python

#Call len(obj) with a dictionary as obj to count the number 
#of key-value pairs in the dictionary.

a_dictionary = {"a": 1, "b": 2}
print(len(a_dictionary))

OUTPUT:
2
Posted by: Guest on October-22-2020

Code answers related to "find number of dictionaries in a list python"

Python Answers by Framework

Browse Popular Code Answers by Language