Computer Science
Write a Python program to count number of items in a dictionary value that is a list.
Answer
my_dict = eval(input("Enter the dictionary: "))
total_count = 0
for value in my_dict.values():
if type(value) is list:
total_count += len(value)
print("Total number of items in lists within the dictionary:", total_count)
Output
Enter the dictionary: {'l1': [1, 2, 3, 4], 'l2': 'Apple', 'l3': [True, False], 'l4': 'Orange'}
Total number of items in lists within the dictionary: 6
Related Questions
Write a Python program to find the three highest values in a dictionary.
Write a Python program to sort a list alphabetically in a dictionary.
Consider the following unsorted list:
105, 99, 10, 43, 62, 8.
Write the passes of bubble sort for sorting the list in ascending order till the 3rd iteration.What will be the status of the following list after the First, Second and Third pass of the insertion sort method used for arranging the following elements in descending order?
28, 44, 97, 34, 50, 87
Note: Show the status of all the elements after each pass very clearly underlining the changes.