vendredi 3 juillet 2015

Python If statement using 'and' with 'in' [duplicate]

This question already has an answer here:

I'm trying to go parse some text and looking for certain patterns. One pattern I'm looking for is strings that contain both ' AS ' and '.'.

Assuming I have a list of strings, I'm using this to find and append select strings to a new list.

list1 = []

for ngram in bigrams:
        if ' AS ' and '.' in ngram:
            list1.append(ngram)

This is not working, it appears to be functioning more like:

    if ' AS ' or '.' in ngram:

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire