How to display all words that contain these characters?

后端 未结 7 1878
后悔当初
后悔当初 2021-01-03 00:05

I have a text file and I want to display all words that contains both z and x characters.

How can I do that ?

7条回答
  •  既然无缘
    2021-01-03 00:47

    If you don't want to have 2 problems:

    for word in file('myfile.txt').read().split():
        if 'x' in word and 'z' in word:
            print word
    

提交回复
热议问题