Monday : Coding Question

Dear Learners,

Embrace the journey of education. Believe in yourself, stay curious, and seek growth. Surround yourself with positivity, celebrate milestones, and learn from setbacks. Your education is a powerful tool for change. Strive to make a difference and pursue your dreams.

Stay motivated and keep learning!

Question:

Write a Python function to find the most frequent element in a given list. If there are multiple elements with the same highest frequency, return the one that appears first. If the list is empty, return None.

Example:

lst = [3, 5, 2, 5, 3, 4, 1, 5, 2, 3]
print(find_most_frequent_element(lst))

Output: 5

lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(find_most_frequent_element(lst))

Output: 1

lst = []
print(find_most_frequent_element(lst))

Output: None

1 Like