# load the data in a dictionary
# dict keys are towns
# and value is another dict with keys 'mean' and 'variancne'
# and values with mean and variance of the respective towns
# Example:
# to_dict_load(data) ->
# {'Rome': {'mean': 66.02499999999999, 'variance': 915.3852083333335},
# 'London': {'mean': 51.199999999999996, 'variance': 57.428333333333335} ... }
defto_dict_load(data):all_towns=data.split("\n")town_wise={}foriinrange(len(all_towns)):town_name,values=all_towns[i].split(":")values=values.split(",")vals=[float(v.split(" ")[1])forvinvalues]mean=sum(vals)/len(vals)variance=sum(map(lambdax:(x-mean)*(x-mean),vals))/len(vals)town_wise[town_name]={'mean':mean,'variance':variance}returntown_wise# returns mean of rainfall in a town according to data
defmean(town,data):dt=to_dict_load(data)iftownindt:returndt[town]['mean']return-1# returns variance of rainfall in a town according to data
defvariance(town,data):dt=to_dict_load(data)iftownindt:returndt[town]['variance']return-1
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python solution