Filtering out non-readable characters

Peter Hansen peter at engcorp.com
Sat Jul 16 16:42:58 EDT 2005


Steven D'Aprano wrote:
> On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen wrote:
>>Bengt Richter wrote:
>>
>>> >>> identity = ''.join([chr(i) for i in xrange(256)])
>>
>>And note that with Python 2.4, in each case the above square brackets 
>>are unnecessary (though harmless), because of the arrival of "generator 
>>expressions" in the language.
> 
> But to use generator expressions, wouldn't you need an extra pair of round
> brackets?
> 
> eg identity = ''.join( ( chr(i) for i in xrange(256) ) )

Come on, Steven.  Don't tell us you didn't have access to a Python 
interpreter to check before you posted:

c:\>python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
 >>> ''.join(chr(c) for c in range(65, 91))
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

-Peter



More information about the Python-list mailing list