0

I am attempting to increment a string that has both letters and numbers in it - each of the characters in the string can either be 0-9 or a-z, no upper case letters.

Ideally I would hope it could be incremented in a +1 fashion in the sense that if the string was o6 to o7 o8 o9 oa ob etc to oz then p0 p1 etc by the way that's a lower base O not a zero

The method I use to increment only works by converting string to int, then incrementing by +1 and cannot be used here.

number = str(int(number) + 1)
In the stars
  • 253
  • 4
  • 17

1 Answers1

1

This question shows you how to do base36 encoding/decoding in Python.

To increment a number that is encoded in base36, you just decode it to an integer, add 1, then encode the result.

number = base36encode(base36decode(number) + 1)
Community
  • 1
  • 1
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Your answer did it for me - the duplicate helped me define the two and number = base36encode(base36decode(number) + 1) did the rest, thanks so much – In the stars Aug 28 '15 at 00:32