Ordered word — it is a word in which letters are displayed in alphabetical order. For example, abbey and dirt . The rest of the words are unordered, for example, gics
The task at hand
This task is taken from the Rosetta Code, and it not as common as it seems from the above description. To get a large number of words, we will use the online dictionary available at at http://www.puzzlers.org/pub/wordlists/unixdict.txt, which contains a collection of approximately 2500 words, and since we are going to use python, we can do this by clearing the dictionary instead of loading it as a text file and then doing some file operations on it.
pip install requests
The approach would be to go through the whole word and compare the values of the ascii elements in pairs until we find a false result, otherwise the word will be ordered.
So this task will be divided into 2 parts:
- Using the queries of the Python library, we get data from the given URL
- Store the content extracted from the URL as a string
- Decode content that is normally encoded on the web using UTF-8
- Transformation long line of content into a wordlist
Search for ordered words
- Traversing a wordlist
- Pairwise value comparison ASCII of each adjacent character in each word
- Storing a false result if the pair is unordered
- Otherwise, print the ordered word
Output: aau: Word is ordered abbe: Word is ordered abbey: Word is ordered abbot: Word is ordered abbott: Word is ordered abc: Word is ordered abe: Word is ordered abel: Word is ordered abet: Word is ordered abo: Word is ordered abort: Word is ordered accent: Word is ordered accept: Word is ordered ........................... ............... ............ ...........................
List Literature: Rosetta Code
This article is courtesy of Palash Nigam . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you’d like to share more information on the topic discussed above.