/helloworld/helloworld1.py
https://bitbucket.org/mariastepanova/good-one · Python · 39 lines · 26 code · 11 blank · 2 comment · 6 complexity · bcb6d7fa39cc423279ac83698ca5ec1d MD5 · raw file
- SPACE = ' '
-
- '''
- >>> splitstring(' xxx yyy')
- [('xxx', 0), ('yyy', 4)]
- >>> splitstring('x y ')
- [('x', 0), ('y', 2)]
- '''
-
-
- def splitstring(s):
- '''
- >>> splitstring(' xxx yyy')
- ['xxx', 'yyy']
- >>> splitstring('x y ')
- ['x', 'y']
- '''
-
- print '*** splitstring: `' + s + '`'
-
- if s == '':
- return []
-
- if s[0] == SPACE:
- return [splitstring(s[1:])
-
- else:
- n = -1
- for e in s:
- n = n+1
- if e == SPACE:
- return [s[:n]] + [splitstring(s[n+1:])]
-
-
-
-
- if __name__ == '__main__':
- import doctest
- doctest.testmod()