I want to check the max length of array elements. Although I can do it with simple code, is there another smart way to implement this in Python 3?
a = [[1,2], [1], [2,2,3,3], [2,2]]
max_len = 0
for d in a:
max_len = len(d) if len(d) > max_len else max_len
print(max_len)
You can do something like this:
max_len = max([len(i) for i in a])
print(max_len)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With