Thanos Mygdalias Thanos Mygdalias - 1 month ago 6
Python Question

List occurrences in list of lists

We have a list containing lists like so:

My_list = [ [1,2,3],[4,5,6],[7,8,9],[1,2,3] ]


Is there an easy way to learn that the list item
[1,2,3]
appears twice in
My_list
? I am not interested in the individual numbers but i am interested in them as a list.

Answer

You may use list.count() in order to find the occurrence of item in the list as:

>>> My_list.count([1, 2, 3])
2
Comments