Checking to see if a list of lists has equal sized lists

前端 未结 4 885
梦谈多话
梦谈多话 2021-01-12 12:32

I need to validate if my list of list has equally sized lists in python

myList1 = [ [1,1] , [1,1]] // This should pass. It has two lists.. both of length 2
m         


        
4条回答
  •  迷失自我
    2021-01-12 13:22

    You could try:

    test = lambda x: len(set(map(len, x))) == 1
    
    test(myList1) # True
    test(myList4) # False
    

    Basically, you get the length of each list and make a set from those lengths, if it contains a single element then each list has the same length

提交回复
热议问题