samedi 10 février 2018

Python: How to use if any("str" in item for item in list)?

The following code snippet below returns an error that global name 'item' is not defined. How do I use if any(...) correctly to search for and print a string if found in a list?

def walk:
    list = ["abc", "some-dir", "another-dir", ".git", "some-other-dir"]
    if any (".git" in item for item in list):
        print item,

Aucun commentaire:

Enregistrer un commentaire