0

someone to explain how I can check if a list in 2D list is repeated more than one time and get the number of repetition.

i can get the half of what i'm looking for with:

grid[i] in grid # check if there is a line in the 2D list

now I want to get the number of repetition

leo
  • 35
  • 6

2 Answers2

1
max(map(grid.count, grid))

Demo:

grid = [[1, 2],
        [3, 4],
        [1, 2]]

print(max(map(grid.count, grid)))      # prints 2

Hmm... after rereading the question, it seems you're actually just asking for grid.count(grid[i]). I guess that seemed so trivial that my mind was reading more into the question. Oh well.

no comment
  • 6,381
  • 4
  • 12
  • 30
0

Try this:

grid.count(max(grid, key=grid.count)))

Or:

max(map(grid.count, grid))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114