Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python increment char a to b az to ba

# Increment char (a -> b, az -> ba)
def inc_char(text, chlist = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
    # Unique and sort
    chlist = ''.join(sorted(set(str(chlist))))
    chlen = len(chlist)
    if not chlen:
        return ''
    text = str(text)
    # Replace all chars but chlist
    text = re.sub('[^' + chlist + ']', '', text)
    if not len(text):
        return chlist[0]
    # Increment
    inc = ''
    over = False
    for i in range(1, len(text)+1):
        lchar = text[-i]
        pos = chlist.find(lchar) + 1
        if pos < chlen:
            inc = chlist[pos] + inc
            over = False
            break
        else:
            inc = chlist[0] + inc
            over = True
    if over:
        inc += chlist[0]
    result = text[0:-len(inc)] + inc
    return result
Comment

PREVIOUS NEXT
Code Example
Python :: optimal alpha jupyter 
Python :: list value extraction using python 
Python :: how to use event of Button in python 
Python :: python script copy and paste 
Python :: How to derive using sympy 
Python :: picture as background of seaborn plot python 
Python :: region error when use service account json file dataproc 
Python :: df.sample(frac=1) 
Python :: newick string python 
Python :: Python: Sending a variable to another script 
Python :: instal django impoer expor 
Python :: flask gunicorn get ip 
Python :: ssl expired python 
Python :: how to calculate the age from date of birth in python 
Python :: for loop to create a set of counters in python 
Python :: python class to tuple 
Python :: django listview 
Python :: Python - Cara Memisahkan String Berdasarkan Beberapa Delimiter 
Python :: Type conversions in python 
Python :: display all rows pandas 
Python :: how to send more than one variables to python using xlwings 
Python :: start a webservice quickly using python2.7 
Python :: compare if 2 numbers are relatively equal 
Python :: spotify python bot 
Python :: playlist discordpy 
Python :: pandas drop unnamed columns grebber 
Python :: pandas convert text duration to minutes 
Python :: comprehensions 
Python :: python classmethod property 
Python :: python3 main.py 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =