I have a string like \'$200,000,000\'
or \'Yan300,000,000\'
I want to split the currency and number, and output a tuple (\'$\', \'200
>>> import itertools
>>> myStr = '$200,000,000'
>>> ''.join(itertools.dropwhile(lambda c: not c.isdigit(), myStr))
'200,000,000'
>>> myStr = 'Yan300,000,000'
>>> ''.join(itertools.dropwhile(lambda c: not c.isdigit(), myStr))
'300,000,000'
Similarly, you could use itertools.takewhile
with the same lambda
function to get the currency sign. However, this might be simpler:
idx = itertools.dropwhile(lambda c: not c.isdigit()).next()
sign, val = myStr[:idx], myStr[idx:]