| | |
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 |
Tag cloud for Python
accessdenied apache application argv beginner book change code color converter dictionary dynamic edit editing enter examples excel file filename float format ftp function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql newb number numbers numeric output parameters parsing path phonebook port prime program programming projects py2exe pygame pyopengl pyqt python random recursion recursive redirect remote reverse scrolledtext server session simple smtp software sprite ssh statictext string strings syntax table tennis terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






