rodukov / textsorter

This simple script sorts all the words in the text by popularity in descending order

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

textsorter

This simple script sorts all the words in the text by popularity in descending order.

How to install it?

Via pip

Now you can use pip3(MacOS & Linux): pip3 install textsorter, windows: pip install textsorter

Via github

git clone https://github.com/rodukov/textsorter
cd textsorter

How to use it?

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}

How do you make the data output look nice?

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   |
+-------+-------+

About

This simple script sorts all the words in the text by popularity in descending order

License:GNU General Public License v3.0


Languages

Language:Python 100.0%