Base62,,#filename:ba
文章由Byrx.net分享于2019-03-23 09:03:18
Base62,,#filename:ba
#filename:base62.py__all__ = ('encode', 'decode',)LETTERS, SIZE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',62DICT = dict( (char,index) for index,char in enumerate(LETTERS) )def div_util(num, dividend): while True: num,index = divmod(num,dividend) yield index if num == 0: returndecode = lambda str_ : sum( DICT[char]*(SIZE**(index)) for index,char in enumerate(str_[::-1]) )encode = lambda num : ''.join( LETTERS[index] for index in div_util(num, SIZE) )[::-1]#该片段来自于http://byrx.net
评论关闭