keywords = ['a', 'b', '(c)']
keywords = [keyword for keyword in keywords if "(" in keyword and ")" in keyword]
I want the output to be:
keywords = ['a', 'b', 'c']
How to modify the list comprehension to get the result without using a loop?
>Solution :
Try strip:
>>> keywords = ['a', 'b', '(c)']
>>> [kw.strip('()') for kw in keywords]
['a', 'b', 'c']
>>>