A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Python program to get the frequency of the elements in a given list of lists
Q:

Write a Python program to get the frequency of the elements in a given list of lists

0

Write a Python program to get the frequency of the elements in a given list of lists.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def count_elements_lists(nums):
    nums = [item for sublist in nums for item in sublist]
    dic_data = {}
    for num in nums:
        if num in dic_data.keys():
            dic_data[num] += 1
        else:
            key = num
            value = 1
            dic_data[key] = value
    return dic_data

nums = [
        [1,2,3,2],
        [4,5,6,2],
        [7,8,9,5],
       ]    
print("Original list of lists:")
print(nums)
print("\nFrequency of the elements in the said list of lists:")
print(count_elements_lists(nums))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now