I have a list:
v = ['4/29/2016 8:25:58 AM', '5/25/2016 2:22:22 PM', 'True', 'Foo', 1, '4/20/1969 4:19:59 PM']
and i would like to iterate through all of the items, replace /
with -
using re.sub
, and skip the element if it is not a string. What am i doing wrong syntactically in this list comprehension to check if x
is a string prior to running my re.sub
?
blah = [ re.sub("/", '-', x ) if isinstance(x, str) for x in v ]
Error output:
blah = [ re.sub("/", '-', x ) if isinstance(x, str) for x in v ]
^
SyntaxError: invalid syntax
Process finished with exit code 1