+ 1

#frequency of characters How can I shorten this code?

I want to get rid of the for loop. How can I minimise the code and output format should not change. https://code.sololearn.com/ch62SfQSH3UH/?ref=app

28th Dec 2019, 5:56 PM
Geek
Geek - avatar
3 ответов
+ 5
This would be my version: s=input() print(*(f'{l}: {s.count(l)}' for l in set(s)), sep='\n')
28th Dec 2019, 6:53 PM
HonFu
HonFu - avatar
+ 4
I did use the for loop. Even if you don't use it by syntax, any function or method that you use will have a for loop running in the background. https://code.sololearn.com/cFWsiNSte2Hq/?ref=app
28th Dec 2019, 6:10 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
import collections for x in collections.Counter(input("Type in a string:-").replace(" ", "")).most_common(): print(x[0], ':', x[1])
28th Dec 2019, 6:44 PM
rodwynnejones
rodwynnejones - avatar