Home > Blockchain >  How can I print out words from a list that contains a particular letter? I know what to do with word
How can I print out words from a list that contains a particular letter? I know what to do with word

Time:11-11

This is the example list

greekAlpha = ["alpha", "beta", "gamma", "epsilon"]

CodePudding user response:

for word in greekAlpha:
    if word.count(letter) > 0:
        print(word)

CodePudding user response:

What about this?

for word in greekAlpha:
    if 'a' in word:
        print(word)

CodePudding user response:

This is One liner approach to condition

[word for word in greekAlpha if "a" in word]
  • Related