how can I find the most common element in the list of list in python?

The result you want [‘apple’, ‘peach’,’banana’] is not the common element. You can make a dictionary to separate different classes of objects.

dict = {}
for item_list in list_of_lists:
    if item_list[0] not in dict:
        dict[item_list[0]] = []
        dict[item_list[0]].append(item_list[1])
    else:
        dict[item_list[0]].append(item_list[1])

This will give you

dict = {'fruit': ['apple', 'peach', 'banana'], 'animal': ['cat', 'sheep']}

Leave a Comment