def word_to_syllable(w,li=[]):
if not w:
return li
pattern = """
########
"""
pattern = re.sub("C","[^aeiou]",pattern)
pattern = re.sub("V","[aeiou]",pattern)
match = re.findall(pattern,w,re.VERBOSE)[0]
#print(li)
li.append(match)
w = w[len(match):]
return word_to_syllable(w,li)
This works okay for the first call, but then local variable li
somehow doesn't get forgotten and new values are just appended to the old ones - instead of string, as name of the function suggests, being split to it's own list. Yeah, if I define my function without default argument and instead say it's empty list later in the call , everything's just fine, but I'm curious about what is exactly happening with this code above.