May-06-2017, 02:33 AM
if any(keyword for s in list):Will just return
True
if keyword is in list.>>> keyword = 'Fi' >>> movie_list = ['Pulp Fiction', 'Fight Club', 'The Matrix', 'The Godfather'] >>> any(keyword for s in movie_list) TrueDon't use
list
as variable name,name it used bye Python.Here you just itertate over list,make no sense as you have used keyword as a variable before.
Now it's just a temporary variable in the loop.
for keyword in list: print(keyword)Just to show something that dos the same:
for rubberduck in list: print(rubberduck)Some hints:
>>> keyword = 'Fi' >>> movie_list = ['Pulp Fiction', 'Fight Club', 'The Matrix', 'The Godfather'] >>> for movie in movie_list: ... if keyword in movie: ... print(movie) Pulp Fiction Fight Club >>> # Or >>> [movie for movie in movie_list if keyword in movie] ['Pulp Fiction', 'Fight Club']