pythonpython-3.x2d

How do you find most duplicates in a 2d list?


I have a 2d list that i would like to return the most duplicates by using a list comprehension. For example, i have a list below

a = [[10, 15, 17,],[20,21,27],[10,15,17],[21,27,28],[21,27,28],[5,10,15],[15,17,20]]

I would like my result to be

b = [[10,15,17],[21,27,28]

Solution

  • One line splitted here:

    [ a[k] 
      for k in range(len(a)) 
      if  a.count( a[k] ) > 1
      and k == a.index( a[k] ) ]