This simple script sorts all the words in the text by popularity in descending order.
Now you can use pip3(MacOS & Linux): pip3 install textsorter
, windows: pip install textsorter
git clone /~https://github.com/rodukov/textsorter
cd textsorter
You can use this script in your projects. You only need to import it:
>>> from textsorter import textsorter
>>> your_text = "Hello, Hello how are you?"
>>> sorted_text = textsorter.sort_text(your_text)
>>> print(sorted_text)
{'Hello': 2, 'how': 1, 'are': 1, 'you': 1}
We will use the beautiful tables module:
pip3 install beautifultable
>>> from beautifultable import BeautifulTable
>>> table = BeautifulTable()
>>> text_sorter_data = {'Hello': 2, 'how': 1, 'are': 1, 'you': 1}
>>> for i in text_sorter_data.items():
... table.rows.append([i[0], i[1]])
...
>>> table.columns.header = ["Word", "Count"]
>>> print(table)
+-------+-------+
| Word | Count |
+-------+-------+
| Hello | 2 |
+-------+-------+
| how | 1 |
+-------+-------+
| are | 1 |
+-------+-------+
| you | 1 |
+-------+-------+