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0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.8, 0.0, 0.4, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.2, 5.0, 0.6, 4.2, 0.0, 0.0, 7.0, 0.0, 2.4, 2.0, 2.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 6.6, 0.0, 0.0, 4.2, 2.2, 0.0, 0.0, 0.0, 2.8, 2.0, 0.0, 0.2, 0.8, 1.8, 2.8, 7.2, 2.0, 0.6, 1.6, 0.0, 9.2, 0.6, 0.0, 7.8, 0.6, 0.0, 0.6, 0.2, 0.0, 0.0, 0.0, 0.4, 0.2, 4.8, 0.8, 3.2, 1.2, 0.2, 0.0, 0.2, 2.0, 1.4, 0.0, 21.4, 0.2, 0.0, 0.2, 0.0, 0.0, 0.0, 0.0, 0.4, 1.6, 0.4, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.4, 0.2, 0.0, 2.4, 0.2, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.6, 0.0, 0.0, 0.0, 0.2, 11.4, 0.2, 0.0, 0.4, 0.0, 4.4, 6.0, 0.4, 1.4, 1.4, 0.4, 0.0, 0.0, 3.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.6, 4.2, 0.0, 24.8, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4, 3.4, 1.4, 0.2, 0.0, 0.0]}

There are 3 keys, NSW, QLD and VIC. I want to find the minimum out of each list, then print the highest number ouf these 'minimums' possibly through ascribing a value

THIS IS A SECTION of a larger question: What I have done so far is,

rainfall_and_state = {}
is_first_line = True

for row in open("climate_data_2017.csv"):
  if is_first_line:
    is_first_line = False
  else:
    values = row.split(",")
    month = values[0].split("-")[1]
    rainfall = float(values[6])
    state = values[1]

    if state in rainfall_and_state:
      rainfall_and_state[state].append(rainfall)
    else:
      rainfall_and_state[state] = [rainfall]

this section is wrong i think

minimum = {}
for key in rainfall_and_state:
  rainfalls = rainfall_and_state[key]
  minimum_rainfall = min(rainfall_and_state)
  minimum[key] = minimum_rainfall

print(rainfall_and_state)

if you want me to attach the larger question, I can do so if it better explains

Minimum of each list

>>> l = [(k, min(v)) for k,v in d.items()] 

[('VIC', 0.0), ('QLD', 0.2), ('NSW', 0.2)]

Max among them:

>>> max(x[1] for x in l)

0.2

To get the key, value:

>>> max(l, key=lambda x: x[1])

('QLD', 0.2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM