+ 2

Can anybody explain line no. 14 in this code?

https://code.sololearn.com/cXhPHt7ZZv2E/?ref=app

3rd Jan 2019, 6:04 PM
shreyash joshi
shreyash joshi - avatar
6 Answers
+ 6
zzz = [key  for (key, value) in freq.items() if value == max] - [] indicates that this is a list comprehension, so the result will be a list - "key, value in freq.items()" will return the items (=key/value pairs) in the dictionary 'freq' and store them in the variables 'key' and 'value' respectively - "key for (key, value) in...": only the key will be saved in the list, not the value - "if value == max": keys will only be saved if their corresponding values equals 'max' => create a list of keys in 'freq' whose values are equal to 'max'
3rd Jan 2019, 6:28 PM
Anna
Anna - avatar
+ 3
Funny: I wrote an answer but didn't stick around long enough to see the obligatory 'no connection'. Should we get used to it and just always expect YourInternetException? ;)
3rd Jan 2019, 6:42 PM
HonFu
HonFu - avatar
+ 3
My answers are sometimes saved even though I get the "no connection" error. Then I try it again... and again... and then my answer is posted five times in a row 🙄
3rd Jan 2019, 6:43 PM
Anna
Anna - avatar
+ 3
That's absolutely true 😂
3rd Jan 2019, 6:47 PM
Anna
Anna - avatar
+ 2
And when you try to erase 4 of them, THEN you get the most terrible streak of 'no connection'.
3rd Jan 2019, 6:45 PM
HonFu
HonFu - avatar
+ 2
Anna thanks for answer, i got it.
4th Jan 2019, 2:38 PM
shreyash joshi
shreyash joshi - avatar