Advertisement
here2share

# text_increment.py

Mar 27th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. # text_incr.py
  2.  
  3. def incr_str(s):
  4.     p = s.rstrip('z')
  5.     r = len(s) - len(p)
  6.     if p: p = p[:-1] + chr(ord(p[-1]) + 1)
  7.     else: p = 'a'
  8.     p += 'a' * r
  9.     return p
  10. #
  11.  
  12. print incr_str('aaa')
  13. print incr_str('zzz')
  14. print incr_str('a')
  15. print incr_str('z')
  16. print incr_str('pizzazz')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement