skip to content
barorin&?

Wordleが解けなくて

/ 1 min read

はじめに

文字列操作の勉強とかを兼ねて作ってみました。
大本の単語リストは下記を使用しています。
google-10000-english/google-10000-english.txt at master · first20hours/google-10000-english · GitHub

内容

import re

# 単語リスト読み込み
with open('google-10000-english.txt', 'r') as f:
    word_list = f.read().splitlines()

# 5文字の単語だけを抽出
five_letter_words = []
for word in list(filter(lambda x: len(x) == 5, word_list)):
    five_letter_words.append(word)

# 検索
reg = '[a-z]{5}' # 正規表現
result_list = [
    # 正規表現にマッチかつaとbを含む単語
    word for word in  five_letter_words \
    if re.match(reg, word) and (('a' in word) and ('b' in word))
]