int_to_base36 and base36_to_int

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def base36_to_int(s):
    return int(s, 36)

def int_to_base36(i):
    digits = "0123456789abcdefghijklmnopqrstuvwxyz"
    factor = 0
    # Find starting factor
    while True:
        factor += 1
        if i < 36 ** factor:
            factor -= 1
            break
    base36 = []
    # Construct base36 representation
    while factor >= 0:
        j = 36 ** factor
        base36.append(digits[i / j])
        i = i % j
        factor -= 1
    return ''.join(base36)

More like this

  1. packjs templatetag by kyprizel 4 years, 5 months ago
  2. ultralize by catellar 9 months ago
  3. base class to easily expose json based web services by jpablo 1 year, 10 months ago
  4. Ensure ugettext is available absolutely everywhere by ElfSternberg 2 years, 11 months ago
  5. Pagination/Filtering Alphabetically by zain 3 years, 2 months ago

Comments

(Forgotten your password?)