sorting out words that have letters in the wrong place

list1 = [
    "hello",
    "saryt",
    "artsy",
    "ahoy"
]

#letters that can't be used
deadletters='hello'

#sorts out words with dead letters
list2 = [w for w in list1 if not(any(set(w) & set(deadletters)))]
print(list2)

#only lets words with "a___y" through
found = [w for w in list2 if (w[0] == 'a') & (w[-1] == 'y')]

print(found)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top