Filtering out non-readable characters

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Jul 16 11:48:10 EDT 2005


On Sat, 16 Jul 2005 10:25:29 -0400, Peter Hansen wrote:

> Bengt Richter wrote:
>>  >>> identity = ''.join([chr(i) for i in xrange(256)])
>>  >>> unprintable = ''.join([c for c in identity if c not in string.printable])
> 
> 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) ) )

with the extra spaces added for clarity.

That is, the brackets after join make the function call, and the nested
brackets make the generator.  That, at least, is my understanding.



-- 
Steven
who is still using Python 2.3, and probably will be for quite some time





More information about the Python-list mailing list