| | |
letters to numbers
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Is there a built-in function to give the value of a letter?
what I mean is
a=1
b=2
c=3
d=4
e=5
f=6
...
something like letval(a) would give me 1
what I mean is
a=1
b=2
c=3
d=4
e=5
f=6
...
something like letval(a) would give me 1
0
#2 Oct 18th, 2009
You mean something like this ...
python Syntax (Toggle Plain Text)
def letval(x): print(x) a = 77 letval(a) # you can just use print(a)
Last edited by vegaseat; Oct 18th, 2009 at 3:18 pm.
May 'the Google' be with you!
0
#3 Oct 18th, 2009
No I don't mean that, that would be stupid.
every letter of the alphabet represents a number
a = the first letter = the first number = 1
b = the second letter = the second number = 2
...
so if I did:
every letter of the alphabet represents a number
a = the first letter = the first number = 1
b = the second letter = the second number = 2
...
so if I did:
python Syntax (Toggle Plain Text)
letval(a) #=1 letval(g) #=7 because g is the seventh letter in the alphabet
Last edited by Kruptein; Oct 18th, 2009 at 3:27 pm.
0
#5 Oct 18th, 2009
hm okay, but in that case I have to make a difference between caps and lowercase letters,... but I will work with that.
0
#6 Oct 18th, 2009
Convert them all to lower case before using ord:
Python Syntax (Toggle Plain Text)
l = l.lower()
Last edited by scru; Oct 18th, 2009 at 5:07 pm.
0
#7 Oct 18th, 2009
If you are only interested in the letter's position in the alphabet, you can use something like this ...
python Syntax (Toggle Plain Text)
import string def letter_position(letter): ucase = string.uppercase pos = ucase.find(letter.upper()) + 1 if pos: print( "%s has position %d in the alphabet" % (letter, pos) ) letter_position('E') letter_position('f') letter_position('a') letter_position('Z') letter_position('8') # a number gives no response
Last edited by vegaseat; Oct 18th, 2009 at 5:22 pm.
May 'the Google' be with you!
![]() |
Similar Threads
- How i can to generate characters of 'n' lenght using letters and numbers by rand() (C++)
- writing a loop with letters not numbers (Python)
- ->ToLower() (Mixing letters and numbers) (C++)
- Textbox allows letters and numbers only (Visual Basic 4 / 5 / 6)
- random letters/numbers (Visual Basic 4 / 5 / 6)
- 3 letters or numbers com/net/org/info/biz/us -or- YPN invite [wanted] (Websites for Sale)
Other Threads in the Python Forum
- Previous Thread: List help...
- Next Thread: Multiple Replies Please
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog data decimals dictionaries dictionary drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule script scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






