What are ordered words?
An ordered word is a word in which the letters appear in alphabetic order. For example abbey & dirt. The rest of the words are unordered for example geeks
The task at hand
This task is taken from Rosetta Code and it is not as mundane as it sounds from the above description. To get a large number of words we will use an online dictionary available on http://www.puzzlers.org/pub/wordlists/unixdict.txt which has a collection of about 2,500 words and since we are gonna be using python we can do that by scraping the dictionary instead of downloading it as a text file and then doing some file handling operations on it.
pip install requests
The approach will be to traverse the whole word and compare the ascii values of elements in pairs until we find a false result otherwise the word will be ordered.
So this task will be divided in 2 parts:
- Using the python library requests we will fetch the data from the given URL
- Store the content fetched from the URL as a string
- Decoding the content which is usually encoded on the web using UTF-8
- Converting the long string of content into a list of words
Finding the ordered words
- Traversing the list of words
- Pairwise comparison of the ASCII value of every adjacent character in each word
- Storing a false result if a pair is unordered
- Otherwise printing 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 ........................... ........................... ...........................
References: Rosetta Code
This article is contributed by Palash Nigam . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Newspaper scraping using Python and News API
- Program to print all distinct elements of a given integer array in Python | Ordered Dictionary
- Implementing web scraping using lxml in Python
- Python | Words extraction from set of characters using dictionary
- Newspaper: Article scraping & curation (Python)
- Implementing Web Scraping in Python with Scrapy
- Python - Remove Dictionary Key Words
- Python - Replace words from Dictionary
- Python - Append Dictionary Keys and Values ( In order ) in dictionary
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert string dictionary to dictionary
- Python - Update dictionary with other dictionary
- Python - Filter dictionary values in heterogenous dictionary
- Python - Replace dictionary value from other dictionary
- Building an undirected graph and finding shortest path using Dictionaries in Python
- Python counter and dictionary intersection example (Make a string using deletion and rearrangement)
- Possible Words using given characters in Python
- Print anagrams together in Python using List and Dictionary
- Python - Cost computation using Frequency and Price dictionary