Question: I have the following code. 

```
import os

products =  [

        {"Product": "S65-85OS04_M2M_GP211_JC222_R6",
         "PlatformName": "winPc",
         "PlatformVariant": "eeprom",
         "DocGeneration": False,
         "BuildStatus": "Pass",
        },

        {"Product": "SC5-01OS19_GP221_JC302_LTE_MTN",
         "PlatformName": "winPc",
         "PlatformVariant": "flash",
         "DocGeneration": False,
         "BuildStatus": "Fail",
         },

        {"Product": "SC5-01OS01_GP211_JC302_LTE_TMO",
         "PlatformName": "winPc",
         "PlatformVariant": "flash",
         "DocGeneration": False,
         "BuildStatus": "Pass",
         }
    ]

class UTE(object):

    def __init__(self, workspace, products, blackList=None):
        for each in products:
            # print each
            if each['Product'] in blackList:
                products.remove(each)
        for each in products:
            print each["Product"]

if __name__ == '__main__':
    ins = UTE('ws', products, ["SC5-01OS01_GP211_JC302_LTE_TMO", "SC5-01OS19_GP221_JC302_LTE_MTN"])

```

Now whenever I run this, it removes only one entry in the dict. For example, in this case it is removing the 2nd entry and that is `SC5-01OS19_GP221_JC302_LTE_MTN`. I believe this is something related to shallow copy..**Am I right ??** If not then how solve this issue?

Answer: 
```
for each in products:
    # print each
    if each['Product'] in blackList:
        products.remove(each)

```

Here you are modifying the list while iterating over it. That would give you unexpected result. A quick fix is: iterate over a copy of the list:

```
for each in products[:]:

```
As explained by AKS, you can use list comprehensions to filter out list elements. In addition, you can use the built in `filter` function:

```
some_integers = range(15)

# via filter
odd_integers = filter(lambda i: i%2 != 0, some_integers)

# via list comprehension
odd_integers = [num for num in some_integers if num %2 != 0]

```

Ultimately, the issue you're running into is that you are modifying your list as you iterate through it. This has been discussed many times, for example: [Modifying list while iterating](https://stackoverflow.com/questions/1637807/modifying-list-while-iterating)