recursively count string

Solutions on MaxInterview for recursively count string by the best coders in the world

showing results for - "recursively count string"
Luca
24 Jan 2019
1def length(s): 
2   if not s:  # test if there are no more characters in the string
3      return 0
4   else:  # maintain a count by adding 1 each time you return
5          # get all but the first character using a slice
6      return 1 + length( s[1:] )