2017-10-11 1 views
0

Je cherche un extrait qui fait des choses comme:python2 chaîne d'augmentation dans un format alphanumérique

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

Vous ne trouvez pas une façon de le faire :(

Je étoffe déjà essayé comme l'utilisation 'aaaa'.encode (' hex ') puis incrémenter, mais ne fonctionne pas :(

Merci pour l'aide,

Cheers!

Répondre

0

Voici une façon de le faire:

# written by 'imerso' to a StackOverflow 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

Merci! Fonctionne bien :) –