Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get character position in alphabet

I'm 90% sure there is a built in function that does this.

I need to find the position of a character in an alphabet. So the character "b" is position 1 (counting from 0), etc. Does anyone know what the function is called?

Thanks in advance!

EDIT: What i'm trying to do is to send all the characters X amount of "steps" back in the alpha bet, so if i have a string with "hi" it would be "gh" if i sent it back one step. There might be a better way of doing it, any tips?

like image 719
qwerty Avatar asked May 08 '11 11:05

qwerty


People also ask

How do you know the position of a letter in the alphabet?

A letter's position in Alphabet can easily be found by performing logical AND operation with the number 31. Note that this is only applicable to letters and not special characters. Every letter has an ASCII value which can be represented in binary form.

How do you get the numeric position of the alphabet in C++?

int position = 'g' - 'a' + 1; In C, char values are convertible to int values and take on their ASCII values. In this case, 'a' is the same as 97 and 'g' is 103. Since the alphabet is contiguous within the ASCII character set, subtracting 'a' from your value gives its relative position.

What position is S in alphabet?

S, or s, is the nineteenth letter in the Modern English alphabet and the ISO basic Latin alphabet.


1 Answers

It is called index. For e.g.

>>> import string >>> string.lowercase.index('b') 1 >>>  

Note: in Python 3, string.lowercase has been renamed to string.ascii_lowercase.

like image 148
Senthil Kumaran Avatar answered Oct 13 '22 07:10

Senthil Kumaran