Remove items from a list

Egbert Bouwman egbert.list at hccnet.nl
Wed Sep 8 12:12:29 CEST 2004


On Wed, Sep 08, 2004 at 03:59:26AM +0000, Stan Cook wrote:
> I was trying to take a list of files in a directory and remove all but the ".dbf" files.  I used the following to try to remove the items, but they would not remove.  Any help would be greatly appreciated.
> 
> x = 0
> for each in _dbases:
>     if each[-4:] <> ".dbf":
>             del each            # also tried:   del _dbases[x]
>     x = x + 1
> 
> I must be doing something wrong, but it acts as though it is....
> 
The answers you received don't tell you what you are doing wrong.
If you replace 'del each' with 'print each' it works,
so it seems that you can not delete elements of a list you are 
looping over. But I would like to know more about it as well.
egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991
========================================================================



More information about the Python-list mailing list