[Tutor] Encoding
Prasad, Ramit
ramit.prasad at jpmorgan.com
Fri Nov 18 18:29:41 CET 2011
On 11/17/2011 8:45 PM, Nidian Job-Smith wrote:
Hi all,
In my programme I am encoding what the user has in-putted.
What the user inputs will in a string, which might a mixture of letters and numbers.
However I only want the letters to be encoded.
========================================================
I am assuming that you meant "only accept characters" and not actual
text encoding. The following example is untested and is limited. It
will not really work with non-ASCII letters (i.e. Unicode).
import string
input_string = raw_input( 'Enter something' ) #use input in Python3
final_input = [] # append to a list instead of concatenating a string
# because it is faster to ''.join( list )
for char in input_string:
if char in string.letters:
final_input.append( char )
input_string = ''.join( final_input )
Ramit
Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423
--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
More information about the Tutor
mailing list