How to count number of unique lists within list?

后端 未结 4 481
心在旅途
心在旅途 2021-01-27 12:10

I\'ve tried using Counter and itertools, but since a list is unhasable, they don\'t work.

My data looks like this: [ [1,2,3], [2,3,4], [1,2,3] ]

I would like to

4条回答
  •  滥情空心
    2021-01-27 12:31

    ll = [ [1,2,3], [2,3,4], [1,2,3] ]
    print(len(set(map(tuple, ll))))
    

    Also, if you wanted to count the occurences of a unique* list:

     print(ll.count([1,2,3]))
    

    *value unique, not reference unique)

提交回复
热议问题