Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > weird strings question

Reply
Thread Tools

weird strings question

 
 
Lucas Raab
Guest
Posts: n/a
 
      02-26-2005
Is it possible to assign a string a numerical value?? For example, in
the string "test" can I assign a number to each letter as in "t" = 45,
"e" = 89, "s" = 54, and so on and so forth??

TIA
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      02-26-2005

Lucas Raab wrote:
> Is it possible to assign a string a numerical value?? For example, in


> the string "test" can I assign a number to each letter as in "t" =

45,
> "e" = 89, "s" = 54, and so on and so forth??
>
> TIA


>>> for c in 'abcd':

.... print c, ord(c)
....
a 97
b 98
c 99
d 100

If that isn't what you mean, you may need to rephrase your question.

 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      02-26-2005
Lucas Raab wrote:
> Is it possible to assign a string a numerical value?? For example, in
> the string "test" can I assign a number to each letter as in "t" = 45,
> "e" = 89, "s" = 54, and so on and so forth??


Use a dictionary with the strings as keys.

string2num = {}
string2num['t'] = 45
string2num['e'] = 89

etc.

--
Robert Kern


"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
Reply With Quote
 
Lucas Raab
Guest
Posts: n/a
 
      02-27-2005
Robert Kern wrote:
> Lucas Raab wrote:
>
>> Is it possible to assign a string a numerical value?? For example, in
>> the string "test" can I assign a number to each letter as in "t" = 45,
>> "e" = 89, "s" = 54, and so on and so forth??

>
>
> Use a dictionary with the strings as keys.
>
> string2num = {}
> string2num['t'] = 45
> string2num['e'] = 89
>
> etc.
>


Thanks. That's what I was looking for, but was just unsure exactly how
to proceed.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A Weird Appearance for a Weird Site Beauregard T. Shagnasty HTML 1 01-21-2011 04:17 PM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 07:10 AM
Re: A Weird Appearance for a Weird Site dorayme HTML 1 01-21-2011 06:51 AM
Re: A Weird Appearance for a Weird Site richard HTML 0 01-21-2011 06:46 AM
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM



Advertisments