I want to find the maximum temperature in a set of data and print the output as "The hottest temperature was x in y" where x and y is temperature and city respectively. I have a code like this:
data = [['Sheffield', '41.2', '35.5', '41.1'],
['Lancaster', '31.3', '40.2', '37.9'],
['Southampton', '34.8', '33.9', '32',],
['Manchester', '41.9', '41.5', '44.2'],
['Bristol', '42.1', '37.1', '42.2']]
hot = []
for row in data:
for item in row:
if item == max(row[1:]):
hot.append(item)
if max(hot) in row:
print "The hottest temperature was {0} in {1}.".format(max(hot),row[0])
The outputs that were produced:
The hottest temperature was 41.2 in Sheffield.
The hottest temperature was 44.2 in Manchester.
Now I am confused with the outputs. I want to print only one line of output which is supposed to be "The hottest temperature was 44.2 in Manchester." since 44.2 is the maximum temperature in the data. Why did "The hottest temperature was 41.2 in Sheffield." is printed too? Where did I get it wrong?