hardvorti.blogg.se

Jumble words out of order
Jumble words out of order




jumble words out of order

#JUMBLE WORDS OUT OF ORDER CODE#

You should only explain once at the beginning how your algorithm work and let your code tell the rest. Instead of always repeating what your dict is doing, you should just explain once what it does when you declare it the code will tell the rest. For example, you could remove: if sorted_word in dict: #Check if sorted_word is already a keyĪnybody who knows how Python dictionaries work will know what this lign is doing, the code is explicit by itself. People simply won't read them, you should only keep the meaningful ones. Hum, first of all, there are way too many comments. Print result, #Trailing, designates that there should be a space between entriesĮlse: #Jumble not found in dictionary print message Results = dict #Get list of words that match jumbleįor result in results: #Loop through list printing results If jumble in dict: #If sorted jumble exists in dictionary Jumble = ''.join(sorted(jumble)) #Sort jumble alphabetical If(jumble = "quit"): #Quit if quit is typed

jumble words out of order jumble words out of order

Jumble = jumble.lower() #Send jumble to lower Jumble = raw_input("Enter a jumble to decode or 'quit': ") #Get input If word not in dict: #Make sure word is not already in the list under the key sorted_wordĭict.append(word) #Add to list under the key sorted_wordĭict = #Create new list with one entry If sorted_word in dict: #Check if sorted_word is already a key Sorted_word = ''.join(sorted(word)) #Alphabetically sort the word Word = word.strip().lower() #Strip newlines and send to lowercase dict = įile = open("/usr/share/dict/words", "r")įor word in file: #Iterate through every word in the dictionary Can I make it much better? I'm sure it can be done. I'm provided with a word and I need to find all the possible combination of it that matches with a given list of words in a file. I need to write code for the given problem:






Jumble words out of order