mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Remove import string and use string methods
This commit is contained in:
		
							parent
							
								
									4737b2348b
								
							
						
					
					
						commit
						4aef41ffe7
					
				
					 1 changed files with 3 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -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:
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
>>> import string
 | 
			
		||||
>>> a = string.split("This is a test string from Andrew.")
 | 
			
		||||
>>> a.sort(lambda x, y: cmp(string.lower(x), string.lower(y)))
 | 
			
		||||
>>> a = "This is a test string from Andrew".split()
 | 
			
		||||
>>> a.sort(lambda x, y: cmp(x.lower(), y.lower()))
 | 
			
		||||
>>> print a
 | 
			
		||||
['a', 'Andrew.', 'from', 'is', 'string', 'test', 'This']
 | 
			
		||||
['a', 'Andrew', 'from', 'is', 'string', 'test', 'This']
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
 | 
			
		||||
This goes through the overhead of converting a word to lower case
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue