Skip to content

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

License

Notifications You must be signed in to change notification settings

rodukov/textsorter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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