+ 2
Can anybody explain line no. 14 in this code?
6 Respostas
+ 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'
+ 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? ;)
+ 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 🙄
+ 3
That's absolutely true 😂
+ 2
And when you try to erase 4 of them, THEN you get the most terrible streak of 'no connection'.
+ 2
Anna thanks for answer, i got it.