+ 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
5 odpowiedzi
+ 5
This would be my version:
s=input()
print(*(f'{l}: {s.count(l)}' for l in set(s)), sep='\n')
+ 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
+ 4
import collections
for x in collections.Counter(input("Type in a string:-").replace(" ", "")).most_common():
print(x[0], ':', x[1])