Re: [pygame] more basic python lists question

2011-11-19 Thread Russell Jones
I don't know if it was intentional, but that's a masterful play on words if
so :)

On 19 November 2011 03:41, Jake b  wrote:

> That's called 'list comprehension':
> http://docs.python.org/tutorial/datastructures.html#list-comprehensions
>
> On Thu, Nov 17, 2011 at 8:14 PM, Lee Buckingham 
> wrote:
>
>>
>>
>>
>>> filenames = [f for f in filenames if f.endswith(".png")]
>>>
>>
>>
>> Slick!  I learn so much listening to you guys and your questions.
>>
>
>
>
> --
> Jake
>


Re: [pygame] more basic python lists question

2011-11-18 Thread Jake b
That's called 'list comprehension':
http://docs.python.org/tutorial/datastructures.html#list-comprehensions

On Thu, Nov 17, 2011 at 8:14 PM, Lee Buckingham wrote:

>
>
>
>> filenames = [f for f in filenames if f.endswith(".png")]
>>
>
>
> Slick!  I learn so much listening to you guys and your questions.
>



-- 
Jake


Re: [pygame] more basic python lists question

2011-11-17 Thread Lee Buckingham
> filenames = [f for f in filenames if f.endswith(".png")]
>


Slick!  I learn so much listening to you guys and your questions.


Re: [pygame] more basic python lists question

2011-11-17 Thread Christopher Night
This is more pythonic (also more efficient):

filenames = [f for f in filenames if f.endswith(".png")]

Your method with the loop won't work in general. Do it like this.

-Christopher

On Thu, Nov 17, 2011 at 1:24 PM, Sean Wolfe  wrote:

> I find myself often iterating a list looking to remove the
> undesireable elements. I want to do this:
>
> for f in filenames:
>if not f.endswith('.png')
>f.delete()
>
> But I find myself having to do this:
>
> for i in range(len(filenames))::
>if not filenames[i].endswith(".png"):
>del filenames[i]
>
>
> I'm wondering if there is a way to do the first option? I suppose I"m
> trying to delete what I'm examining at the same time which maybe is
> why it's problematic.
>
> Thanks!
>
>
> --
> A musician must make music, an artist must paint, a poet must write,
> if he is to be ultimately at peace with himself.
> - Abraham Maslow
>