question regarding list comprehensions
Pat
Pat at junk.com
Mon Oct 20 12:52:24 EDT 2008
Diez B. Roggisch wrote:
> Pat wrote:
>
>> I have written chunks of Python code that look this:
>>
>> new_array = []
>> for a in array:
>> if not len( a ):
>> continue
>> new_array.append( a )
>
> new_array = [a for a in array if len(a)]
>
>> and...
>>
>> string = ""
>> for r in results:
>> if not r.startswith( '#' ):
>> string =+ r
>
>
> "".join(r for r in results if not r.startswith("#"))
>
> Diez
Thank you very much! That's exactly what I was looking for. That's
much cleaner than my code.
This is a great forum and I really appreciate everyone's help.
More information about the Python-list
mailing list