We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f9c1680 commit 72219b8Copy full SHA for 72219b8
stepic/python_fullstack/groupby_example.py
@@ -48,4 +48,20 @@
48
49
print([(i, list(j)) for i, j in itertools.groupby(s)])
50
51
-######################
+######################
52
+"""
53
+Напишите функцию, которая принимает на вход строку слов и возвращает словарь,
54
+содержащий частоту каждого слова в строке. Словарь должен включать слова в качестве ключей и их частоты в качестве значений.
55
56
+
57
58
+from typing import Dict
59
+from itertools import groupby
60
61
62
+def word_frequencies(string):
63
+ return {i:len(list(j)) for i,j in groupby(sorted(string.split()))}
64
+ # Поместите свой код сюда
65
66
+print(word_frequencies('hello world and hello universe'))
67
+print(word_frequencies('hello world'))
0 commit comments