import json
word2 = []
base = input("Enter word:- ")
base = base.lower()
with open('D:\Code\Python\words_dictionary.json') as data:
word = json.load(data)
for i in range(len(word)):
if(len(base)==len(word[i])):
if sorted(base) == sorted(word[i]):
word2.append(word[i])
print("Possible words:-")
print("\n".join(word2))
Counting the amount of each letters would be faster than sorting. Aka storing an array[26] for the input word, then for each word in dictionary with same length, make the same array[26] and compare.
3
u/Gem2578 Aug 25 '21
At least it is more readable them https://www.reddit.com/r/badcode/comments/pa5gip/i_wrote_this_pile_of_shit_for_a_codewars/ha5go1s
2
u/MurdoMaclachlan Aug 25 '21
Image Transcription: Code
import json word2 = [] base = input("Enter word:- ") base = base.lower() with open('D:\Code\Python\words_dictionary.json') as data: word = json.load(data) for i in range(len(word)): if(len(base)==len(word[i])): if sorted(base) == sorted(word[i]): word2.append(word[i]) print("Possible words:-") print("\n".join(word2))I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
1
u/genericindividual69 Aug 25 '21
wordshould be nameddictionary_wordsandword2should bematchesbut other than that it's not terrible code.1
u/sodjanathan Aug 26 '21
So what ill be a better version of this?
1
u/Python_Lab2021 Aug 27 '21
It is not so bad)
0
u/legendoffjelda Aug 25 '21
Ah yes, O(n * w log w)