Jan-07-2022, 09:38 PM
Line 6 won't work. You're asking if the current value is a match object. I presume that your current values are strings, so that won't ever succeed.
You're using "findall", but findall only hands you the bits that match, not the non-digit bits (which you presumably want to retain). Possibly you want to use re.sub instead. Then if your num2words can take a match object instead of an int, you could write it as:
You're using "findall", but findall only hands you the bits that match, not the non-digit bits (which you presumably want to retain). Possibly you want to use re.sub instead. Then if your num2words can take a match object instead of an int, you could write it as:
sub match2words(m): digits = m.group() # convert this with whatever means you have return "converted" for key, value in cybc.items(): new_value = re.sub(r'\d+', match2words, value) cybc[key] = new_value print('Test to show updated value', new_value) print('Test to show keys', key)