Dec-17-2017, 10:45 AM
So I have this problem: I have a month and for each day in the month I have a city with a certain level of pollutin. Some cities can also be missing for a certain day. I have data for all 31 days but I made it shorter. Like this --->
januar = {
1: {'Texas': 126, 'Moscow': 64, 'Berlin': 57, 'Athens': 35,},
2: {'Texas': 53, 'Moscow': 56, 'Berlin': 58,},
3: {'Texas': 34, 'Moscow': 71, 'Berlin': 48, Athens': 55,}
}
I have to define a function that returns for each city the number of days when pollution was above 50.
In the second part of the task I have to define a function that returns average level of pollution for each city of the month but only for cities that don't have missing values so I can't calculate for Athens for example.
I started the first part like this:
I tried the second part of the task in several different ways googling similar problems but all that happend was that the outcome was incorrent and I am more and more confused.
Any kind of help would be very welcome.
P.S. I am a professional athlete and have very limited amount of time to study python but I'd really like to understand it. I understand the easy and short examples but here where I have a dictionary in a dictionary it gets me confused.
I wish you a nice Sunday.
Thank you in advance,
Klara
januar = {
1: {'Texas': 126, 'Moscow': 64, 'Berlin': 57, 'Athens': 35,},
2: {'Texas': 53, 'Moscow': 56, 'Berlin': 58,},
3: {'Texas': 34, 'Moscow': 71, 'Berlin': 48, Athens': 55,}
}
I have to define a function that returns for each city the number of days when pollution was above 50.
In the second part of the task I have to define a function that returns average level of pollution for each city of the month but only for cities that don't have missing values so I can't calculate for Athens for example.
I started the first part like this:
def number_of_polluted_days(januar): k = {} for day, TX, MS, BE, ATH in januar.items(): if TX not in k: k[city]=0 if k[city]>=50: k[city] += 1 if MS not in k: k[city]=0 if k[city]>=50: k[city] += 1 if BE not in k: k[city]=0 if k[city]>=50: k[city] += 1 if ATH not in k: k[city]=0 if k[city]>=50: k[city] += 1I get this message: ValueError: not enough values to unpack (expected 14, got 2)
I tried the second part of the task in several different ways googling similar problems but all that happend was that the outcome was incorrent and I am more and more confused.
Any kind of help would be very welcome.
P.S. I am a professional athlete and have very limited amount of time to study python but I'd really like to understand it. I understand the easy and short examples but here where I have a dictionary in a dictionary it gets me confused.
I wish you a nice Sunday.
Thank you in advance,
Klara