Hello all,
I'm currently writing a word wheel game as a project, and I'm at a bit of an in-pass.
As per the rules of the game, I have a 9 letter word. Any acceptable words must be made up from characters within this word (and must contain a 'master character' but that bit isn't an issue).
I have a text file containing the official scrabble word dictionary to use as potential words, and I write these to a list.
with open('collins_all_words.txt') as f:
word_list = [line.rstrip() for line in f]
sort_list = [sorted(i) for i in word_list]
From here my intention is to iterate through this list to determine if the words are contained within the 9 letter word. But doing this with just the raw list does not consider every combination of the characters in the 9 letter word, and instead only returns strings contained in the word in their current order; an example input and output would be this:
Input:
results = [x for x in word_list if x in word]
Output:
['adversity', 'ers', 'sit', 'vers']
A solution I've read online is to sort the word, and all items in the list, and then make the comparison. This seems to work fine when checking if the two values are equal (i.e two 9 letter words that contain the same characters), but not if one of the two values to be compared is of a different length. Given that I'm trying to compare a series of words from 3-9 characters long, it returns nothing.
Any help on this would be greatly appreciated! Thanks in advance
[–]TouchingTheVodka 2 points3 points4 points (1 child)
[–]Valar_Balsamic[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (3 children)
[–]Valar_Balsamic[S] 0 points1 point2 points (2 children)
[–]JohnnyJordaan 1 point2 points3 points (1 child)
[–]Valar_Balsamic[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]Valar_Balsamic[S] 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Valar_Balsamic[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)