python编程有一段英文(内容可自行确定): In a functional program, input flows through a set of functions. Each function operates on its input and produces some output. Functional style discourages functions with side effects that modify internal state or make other changes that aren’t visible in the function’s return value. Functions that have no side effects at all are called purely functional. Avoiding side effects means not using data structures that get updated as a program runs; every function’s output must only depend on its input. (1)统计该段文字有多少个单词及每个单词出现的次数; (2)如果不计算 of、a、the,给出出现频率最高的 5 个单词及其出现的次数
时间: 2024-03-09 09:45:03 浏览: 73
好的,我来回答你的问题:
1. 统计该段文字有多少个单词及每个单词出现的次数:
该段文字共有 66 个单词,每个单词出现的次数如下:
```
{'In': 1, 'a': 2, 'functional': 2, 'program,': 1, 'input': 2, 'flows': 1, 'through': 1, 'set': 1, 'of': 2, 'functions.': 1, 'Each': 1, 'function': 3, 'operates': 1, 'on': 1, 'its': 1, 'and': 1, 'produces': 1, 'some': 1, 'output.': 1, 'style': 1, 'discourages': 1, 'functions': 2, 'with': 1, 'side': 2, 'effects': 2, 'that': 3, 'modify': 1, 'internal': 1, 'state': 1, 'or': 1, 'make': 1, 'other': 1, 'changes': 1, 'aren’t': 1, 'visible': 1, 'in': 1, 'the': 1, 'function’s': 2, 'return': 1, 'value.': 1, 'Functions': 1, 'have': 1, 'no': 1, 'at': 1, 'all': 1, 'called': 1, 'purely': 1, 'functional.': 1, 'Avoiding': 1, 'means': 1, 'not': 1, 'using': 1, 'data': 1, 'structures': 1, 'get': 1, 'updated': 1, 'as': 1, 'runs;': 1, 'every': 1, 'output': 1, 'must': 1, 'only': 1, 'depend': 1, 'on.': 1}
```
2. 如果不计算 of、a、the,给出出现频率最高的 5 个单词及其出现的次数:
除了 of、a、the 这三个单词以外,出现频率最高的 5 个单词及其出现的次数如下:
```
[('functional', 2), ('input', 2), ('functions', 2), ('side', 2), ('function', 3)]
```
阅读全文