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
def equalSizes(*args):
"""
# This should pass. It has two lists.. both of length 2
>>> equalSizes([1,1] , [1,1])
True
# This should pass, It has three lists.. all of length 3
>>> equalSizes([1,1,1] , [1,1,1], [1,1,1])
True
# This should pass, It has three lists.. all of length 2
>>> equalSizes([1,1] , [1,1], [1,1])
True
# This should FAIL. It has three list.. one of which is different that the other
>>> equalSizes([1,1,] , [1,1,1], [1,1,1])
False
"""
len0 = len(args[0])
return all(len(x) == len0 for x in args[1:])
To test it save it to a file so.py
and run it like this:
$ python -m doctest so.py -v
Trying:
equalSizes([1,1] , [1,1])
Expecting:
True
ok
Trying:
equalSizes([1,1,1] , [1,1,1], [1,1,1])
Expecting:
True
ok
Trying:
equalSizes([1,1] , [1,1], [1,1])
Expecting:
True
ok
Trying:
equalSizes([1,1,] , [1,1,1], [1,1,1])
Expecting:
False
ok