Commit 4aef41ff authored by Neal Norwitz's avatar Neal Norwitz

Remove import string and use string methods

parent 4737b234
...@@ -110,11 +110,10 @@ types, do the forward sort first, then use the \method{reverse()} method. ...@@ -110,11 +110,10 @@ types, do the forward sort first, then use the \method{reverse()} method.
Here's a case-insensitive string comparison using a \keyword{lambda} function: Here's a case-insensitive string comparison using a \keyword{lambda} function:
\begin{verbatim} \begin{verbatim}
>>> import string >>> a = "This is a test string from Andrew".split()
>>> a = string.split("This is a test string from Andrew.") >>> a.sort(lambda x, y: cmp(x.lower(), y.lower()))
>>> a.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
>>> print a >>> print a
['a', 'Andrew.', 'from', 'is', 'string', 'test', 'This'] ['a', 'Andrew', 'from', 'is', 'string', 'test', 'This']
\end{verbatim} \end{verbatim}
This goes through the overhead of converting a word to lower case This goes through the overhead of converting a word to lower case
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment