Write a python that reads several lines of text and print a table indicating number of one-letter words, two-letter words, etc.appearing in the text.
For example, the phrase; Whether 'tis nobler in the mind to suffer.
The output will be:
Word length Occurrences
1 0
2 2
3 1
4 2 (including 'tis)
5 0
6 2
7 1
import pandas as pd
words = pd.Series(['Hello', 'World','dd', 'd',
])
print("Given Words:")
print(words)
rst = words.map(lambda calc: len(calc))
print("Words counts")
print(rst)
Comments
Leave a comment