letters = ['a', 'b', 'c', 'd', 'e', 'f']
list(filter(lambda x : print(x) if 'e' in x ,letters))
SyntaxError: invalid syntax
letters = ['a', 'b', 'c', 'd', 'e', 'f']
list(filter(lambda x : print(x) if 'e' in x ,letters))
SyntaxError: invalid syntax
you are getting this "invalid syntax" error because you are applying filter for list letters. For
x=="e"or"e" in xyou are returning item of list as it is but for other value you have to return something.You can add else condition like below:
Output:
if you use jupyter you will get this as output otherwise you have to print that list.
For printing directly you can do this:
Output:
I hope I understood your question properly.
Other reference for printing in lambda Python documentation, Why doesn't print work in a lambda?
Conclusion: "Add else condition for
if 'e' not in x"