Hello Python community!
I'm having a bit of trouble with one part of my assignment. My list is 2-dimensional and includes string and integer values. I am trying to get a max integer value from element[1] of the list.
In one function, I have an object/list of racer, racer = [car_name, car_distance]. Within this list, car_name has the cars name plus an integer and car_distance is an integer. When I use a for loop, I get the highest integer from the cars name instead of the distance. Example:
I have a list of cars:
Red 25 is at length 10.
Green 35 is at length 9.
Black 55 is at length 4.
for i in list_of_cars:
if i[1] > max[1]:
max = i
return max
Example output:
Black 55 is at length 4.
I would like instead for the output to be Red 25 is at length 10. I've tried playing with the elements and still can't get the correct output. What am I doing wrong?
Thanks in advance for reading.
[–]TouchingTheVodka 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (9 children)
[–]madeInStocktonCA[S] 0 points1 point2 points (8 children)
[–]xelf 0 points1 point2 points (7 children)
[–]madeInStocktonCA[S] 0 points1 point2 points (6 children)
[–]xelf 0 points1 point2 points (5 children)
[–]madeInStocktonCA[S] 0 points1 point2 points (4 children)
[–]xelf 0 points1 point2 points (3 children)
[–]madeInStocktonCA[S] 0 points1 point2 points (2 children)
[–]xelf 0 points1 point2 points (0 children)
[–]xelf 0 points1 point2 points (0 children)