I wrote this function to read a list of words representing a number and pair 1-9 digits with multipliers.
def listpairs(element):
pair = []
for word in enumerate(element):
pair.append(word[1])
if word[1] in denoms:
yield pair
pair.clear()
if word[1] in digits and word[0] == (len(element)-1):
yield pair
When I try it with a test string, it gives this:
list(listpairs('two hundred three ten four'.split())
[['four'], ['four'], ['four']]
If I replace yield with print(pair), it gives the expected output:
['two', 'hundred']
['three', 'ten']
['four']
Why does this happen? Is yield the wrong tool here?