If I have a nested list as follows:
foods = [['Category', 'Carbs', 'Calories'], ['SWEET POTATO', '23.4', '100'], ['TOMATOES', '5.1', '23'], ['BEETS', '16.28', '65'], ['LETTUCE', '2.23', '13']]
I want to find and print the sublist with the lowest Calorie count. I have tried the following:
lowcal = foods[0]
for x in foods:
if x[2] < lowcal[2]:
lowcal = x
else:
continue
print (lowcal)
But I am getting the wrong output, I am getting: `['SWEET POTATO', '23.4', '100']
When I should be getting: ['LETTUCE', '2.23', '13']