I have a list: aa=["tea","tee","tea_N","tee_N"]
I want to get the elements with last two characters are "_N".
The result is like: ["tea_N","tee_N"]
How could I do this? Thanks!
I have a list: aa=["tea","tee","tea_N","tee_N"]
I want to get the elements with last two characters are "_N".
The result is like: ["tea_N","tee_N"]
How could I do this? Thanks!
list(filter(lambda x: x.endswith("_N"), aa))
See documentation for filter
and str.endswith
.
Equivalent list comprehension:
[x for x in aa if x.endswith("_N")]