> filenames = [f for f in filenames if f.endswith(".png")]
>
Slick! I learn so much listening to you guys and your questions.
On Thu, Nov 17, 2011 at 1:32 PM, Sean Wolfe wrote:
> if not f.endswith('.png')
> for f in filenames:
> filenames.remove(f)
>
> Along with lots of warnings to copy from one list to another rather
> than delete on an iterating list. But really how much harm could it
> do? lol... I think
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
ah! google is my friend.
for f in filenames:
if not f.endswith('.png')
filenames.remove(f)
Along with lots of warnings to copy from one list to another rather
than delete on an iterating list. But really how much harm could it
do? lol... I think.
On Thu, Nov 17, 2011 at 3:24 PM, Sean
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"):