gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
how to correctly measure my dict in python?
- User
how to correctly measure my dict in python?
- Assistant
You can measure the length of a dictionary in Python using the len() function. This function returns the number of key-value pairs in the dictionary.
Example:
my_dict = {'a': 1, 'b': 2, 'c': 3} print(len(my_dict)) # Output: 3Alternatively, you can loop through the dictionary's keys or values and count them manually:
count = 0 for key in my_dict: count += 1 print(count) # Output: 3