Since you haven't given the desired result, I'm not sure that my decision suits you, that's my option:from collections import Counter
from collections import namedtuple
import sys
def data():
with open(sys.argv[1], 'r') as file:
return file.read().strip()
def first(arg): # Подсчет слов
return f'Результат первой функции {len(arg.split())}\n'
def two(arg): # Слово и его кол-во
return f'Результат второй функции {Counter(arg.split())}\n'
def three(arg): # Слово и его кол-во в виде namedtuple
name = namedtuple('NAME', ['word', 'count'])
return f'Результат третьей функции {tuple(name(word, arg.count(word)) for word in set(arg.split()))}'
Use: In launching the crypt, give 1 parameter in cmd the way to the file, and then:print(first(data()))
print(two(data()))
print(three(data()))
The result of the data you gave on the question:Результат первой функции 37
Результат второй функции Counter({'and': 6, 'cloud': 4, 'in': 3, 'Python,': 3, 'document': 3, 'for': 3, 'Design,': 2, 'develop,': 2, 'test': 2, 'applications': 2, 'API': 2, 'services.': 2, 'maintain': 1, 'design,': 1, 'services': 1})
Результат третьей функции (NAME(word='API', count=2), NAME(word='cloud', count=4), NAME(word='document', count=3), NAME(word='Python,', count=3), NAME(word='for', count=3), NAME(word='services.', count=2), NAME(word='test', count=2), NAME(word='in', count=5), NAME(word='Design,', count=2), NAME(word='develop,', count=2), NAME(word='applications', count=2), NAME(word='services', count=3), NAME(word='and', count=6), NAME(word='design,', count=1), NAME(word='maintain', count=1))