Python Write a recursive function checks that take a string
Python: Write a recursive function check(s) that take a string representing a password as input and returns all the characters that are digits ( 0 -9)
Solution
def check(s):
if len(s) == 0:
return \"\";
else:
if s[:1] >= \'0\' and s[:1] <= \'9\':
return \'\'.join(s[:1]) + check(s[1:]);
else:
return \'\' + check(s[1:]);
print check (\'pass12pass34\')
Output:
sh4.3$ python main.py
1234
