Mapping and Filtering Help for Lists

Arnaud Delobelle arnodel at googlemail.com
Sun Apr 27 14:52:35 EDT 2008


Zethex <zethex at hotmail.com> writes:

> Thank you a lot!
>
> Another quick couple of questions.
>
> How can i make it so it removes special operators such as ? ! or doesnt
> include them?

As you are doing lots of string manipulations, I advise you to read
the section of the python documentation on strings (link below).  This
way you will get a good idea of what can be done out of the box with
strings in python.

http://docs.python.org/lib/string-methods.html

(Or type help(str) from the interactive prompt)

For the particular task of removing a character, you may be interested
in the replace() method.

> and
>
> I need to lowercase the words so should i use sentence = sentence.lower()?

Yes.

Or you could combine the two by using the translate() method. E.g.

>>> table = ''.join(chr(c).lower() for c in range(256))
>>> 'You! are Free??'.translate(table, '!?')
'you are free'

HTH

-- 
Arnaud



More information about the Python-list mailing list