When i run the following
def max(L):
m = L[0][0]
for item in L:
if item[0] > m:
m = item
return m
L = [[20, 10], [10, 20], [30, 20],[12,16]]
print(max(L))
i get the error
TypeError: unorderable types: int() > list()
at line 4. The confusion comes when i try to get the len()
of both members. So from the error message it's reasonable to assume m
is the list so i run
def max(L):
m = L[0][0]
for item in L:
len(m)
if item[0] > m:
m = item
return m
L = [[20, 10], [10, 20], [30, 20],[12,16]]
print(max(L))
and get the error len(m) TypeError: object of type 'int' has no len()
. Ok so the only option left is that item[0]
is the list... so similarly
def max(L):
m = L[0][0]
for item in L:
len(item[0])
if item[0] > m:
m = item
return m
L = [[20, 10], [10, 20], [30, 20],[12,16]]
print(max(L))
and i get the same error: len(item[0]) TypeError: object of type 'int' has no len()
. Since I'm somewhat certain you can compare 2 ints, I have a hard time understanding what to do about the error originally stated.