The below program finds words like code/cope/coje etc. and returns the count of matches. However my return function is not giving me an output. print(len(matches)) gives the right output but I need to use return. I see in this question that 'findall' is a more straightforward method, but I want to use finditer for now. Why isn't this return statement correct? I'm actually facing this problem in frequently as I write programs to learn python. I was unable to pick the answer from these references one,two
import re
mystr = "codexxxcmkkaicopemkmaskdmcone"
def count_code (char):
pattern = re.compile (r'co\we')
matches = pattern.finditer(char)
result = tuple (matches)
return len(result)
count_code(mystr)
count_code (mystr) didn't return anything, and did not return an error. See here : repl.it
returnstatement looks fine, but you're not actually calling the function anywhere.