[Python] Alphabetic increment pattern in python - a-z, aa-az,ba-bz…aaa-azz

Discussão em 'Python' iniciado por Stack, Abril 18, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to work out how to achieve an alphabetic increment that is ran over many items as part of a renamer

    I am using chr() and ord() to retrieve the next letter increment after a starting letter such as

    startletter = ‘a’
    bb = 0
    preletters = ‘’
    pinc + 1
    for o in objects:
    newchar = chr(ord(startletter) + bb)
    #rename here such as joining the preletters with the newchar
    bb = bb + 1


    I then check if the newchar was ‘z’ and then if so make the preletter as follows

    if newchar == ‘z’:
    preletters = chr(pinc)
    pinc = pinc + 1


    I am a bit lost to make this more efficient , ideally what I want should produce a pattern such as

    a,b,c,d …z for the first 26 items

    and then start doubling the letters like this

    aa,ab,ac,ad…az
    ba,bb,bc…..bz


    once we hit zz, we’d then need to triple them to

    aaa, aab, aac etc etc

    Any help appreciated

    Continue reading...

Compartilhe esta Página