print divmod(1024, 26) # 39
print chr(39 + ord('A') - 1) # g

but:

AA, AB etc, how to convert this to number?

Recommended Answers

All 3 Replies

If I understand your question, you asking what number is aa in base 26:

int('aa',26)
270

If I understand your question, you asking what number is aa in base 26:

int('aa',26)
270

Alphabet:

a, b, c, ....., z (there are 26 standard), and aa = 27 and ab = 28.

It's my idea.

Here I prepare list of values and multiply by positional radix 26 power.

startpoint=ord('a')-1
sum( 26**value*num
     for value,num in enumerate(reversed([ord(char)-startpoint
					  for char in 'bc'])))

55

But how would you express zero?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.