I have the following code:
[mc.split('$', 1)[-1] for mc in marketCapsUnclean if 'B' in mc]
Which transforms something like:
['blabla $10M', 'blabla $10B']
into
['$10B']
I would like instead to get a value for the elements which don't pass the if
test, like this:
['N/A', '$10B']
I would like to do something like:
[mc.split('$', 1)[-1] for mc in marketCapsUnclean if 'B' in mc else 'N/A']
But this is not legal syntax.
So is there a way to achieve something similar with a for comprehension?