Ethan McRae Ethan McRae - 1 year ago 39
Python Question

Defining the alphabet to any letter string to then later use to check if a word has a certain amount of characters

This is what I have so far:

alphabet = "a" or "b" or "c" or "d" or "e" or "f" or \
"g" or "h" or "i" or "j" or "k" or "l" or \
"m" or "n" or "o" or "p" or "q" or "r" or \
"s" or "t" or "u" or "v" or "w" or "x" or \
"y" or "z"

letter_word_3 = any(alphabet + alphabet + alphabet)

print("Testing: ice")

if "ice" == letter_word_3:

print("Worked!")

else:

print("Didn't work")

print(letter_word_3) # just to see


I want to be able to eventually scan a document and have it pick out 3 letter words but I can't get this portion to work. I am new to coding in general and python is the first language I've learned so I am probably making a big stupid mistake.

Answer Source
words = [word for word in line.split() if len(word) == 3 and all(ch in ascii_lowercase for ch in word)]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download