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:
Search for ordered words
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.