Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Alphabetic increment pattern in python - a-z, aa-az,ba-bz...aaa-azz

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,...

Any help appreciated.

Answer*

Draft saved
Draft discarded
Cancel

lang-py

AltStyle によって変換されたページ (->オリジナル) /