Answer the question
In order to leave comments, you need to log in
Is it possible to optimize this code?
I can write code, but now I am learning to write competent and optimized code.
This program takes any word and writes to the dictionary how many times each letter of the word was repeated, but is it possible to write better (shorter) using for example **kwargs?
word = input()
lib = {}
for letter in word:
lib[letter] = word.count(letter)
print(lib)
# hello
# {'h': 1, 'e': 1, 'l': 2, 'o': 1}
Answer the question
In order to leave comments, you need to log in
from collections import Counter
lib = Counter(input('Введите слово:\n'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question