Python2增量串

问题描述:

我正在寻找一个片断它不喜欢的东西:Python2增量串

from 'abcd8' string 
i want to increment it like 'abcd9' then 'abcda' ... >'abcdz' and next  'abce0', 'abce1' ... 'abcez', 'abcf0' .... 

无法找到一个方法来做到这一点:(

我已经尝试过的东西一样使用'aaaa'.encode(' 十六进制“),然后增加它,但没有工作:(

感谢您的帮助,

干杯!

这是一种方法:

# written by 'imerso' to a * answer 
def increment(os): 
    s = list(os) 
    p = len(os)-1 

    while (p >= 0): 
     s[p] = chr(ord(s[p]) + 1) 

     if s[p] > 'z': 
      s[p] = '0' 
      p -= 1 
      continue 

     if s[p] > '9' and s[p] < 'a': 
      s[p] = 'a' 

     return ''.join(s) 


s = raw_input("String: ") 

for x in range(1, 32): 
    s = increment(s) 
    print s 
+0

谢谢!!工作正常 :) –