'Python wordlist creation

So far I am creating a world based game the only thing I need help with is creating a wordlist without having to type each word or re formate hundreds into the correct formatting. Any tips?

so far I have this:

fiveLetterWords = ["abuse", "adult", "drama", "drain", "enemy", "entry", "catch", "could", "would", "track", "train", "plain", "plane"]
sixLetterWords = ["people", "things", "really", "abroad", "accept", "belief", "scraps", "trashy", "camera", "create"]

I would like to have a few more words than this and if there's a site that has this listed in this format comment it thanks!



Solution 1:[1]

If you are on a Unix like OS, you can use the words list:

words={}
with open('/usr/share/dict/words') as f: # /usr/dict/words on some
    for word in (w.rstrip() for w in f):
        words.setdefault(len(word), []).append(word)

If you only want words of a certain length, you can filter them:

words={}
with open('//usr/share/dict/words') as f:
    for word in (w for w in (w.rstrip() for w in f) if 4<=len(w)<=6):
        words.setdefault(len(word), []).append(word)

Solution 2:[2]

Search for the most frequent English words in Kaggle datasets. then you can grab those which contain 5, 6, or ... letters. also, you can use this dataset that contains the most frequent 5 letters meaningful English words that is a combination of two datasets and without any repetition.

simply use this line of code to read the .csv file:

import pandas as pd
pd.read_csv("frequent_5_char_words.csv" , sep=" " , header=None)

Solution 3:[3]

These files are from the wordle game therefore only have 5 letter words.

Download the files from allowed guess list and allowed answer list (by clicking download zip) then unzipping them and putting them into the same directory as your script. You can run this to read in those words and use them as part of your wordle game.

def read_from_txt_file(filename):
    with open('wordle-allowed-guesses.txt', 'r') as file:
        file_list = [item[:-1] for item in file] # using [:-1] to get rid of the newline character
    return file_list

guess_list = read_from_txt_file('wordle-allowed-guesses.txt')
answer_list = read_from_txt_file('wordle-answers-alphabetical.txt')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Andrew Ryan