Question: I have an array of complex *dict* that have some value as a string "NULL" and I want to remove, my dict looks like this:

```
d = [{
  "key1": "value1",
  "key2": {
    "key3": "value3",
    "key4": "NULL",
    "z": {
       "z1": "NULL",
       "z2": "zzz",
    },
  },
  "key5": "NULL"
}, {
  "KEY": "NULL",
  "AAA": "BBB",
}]

```

And I want to wipe out all keys that have **NULL** as value

Like this:

`[{"key1": "value1", "key2": {"key3": "value3", "z": {"z2": "zzz"}}}, {"AAA": "BBB"}]`

I am using Python 3.9, so it is possible to use walrus operator.

Answer: 
Here is how you can do this with recursion:

```
def remove_null(d):
    if isinstance(d, list):
        for i in d:
            remove_null(i)
    elif isinstance(d, dict):
        for k, v in d.copy().items():
            if v == 'NULL':
                d.pop(k)
            else:
                remove_null(v)

d = [{
  "key1": "value1",
  "key2": {
    "key3": "value3",
    "key4": "NULL",
    "z": {
       "z1": "NULL",
       "z2": "zzz",
    },
  },
  "key5": "NULL"
}, {
  "KEY": "NULL",
  "AAA": "BBB",
}]

remove_null(d)
print(d)

```

Output:

```
[{"key1": "value1", "key2": {"key3": "value3", "z": {"z2": "zzz"}}}, {"AAA": "BBB"}]

```
> 
> I am using Python 3.9, so it is possible to use walrus operator.
> 
> 
> 

Well then, let's throw one in there since no one else did:

```
from collections import deque

def remove_null(thing):
    if isinstance(thing, list):
        deque(map(remove_null, thing), maxlen=0)
    elif isinstance(thing, dict):
        for key in thing.copy():
            if (value := thing[key]) == 'NULL':
                del thing[key]
            else:
                remove_null(value)

```

Note that I'm using `map` instead of a loop to show an alternative to the other answers. However, this creates the same situation that I commented on @AnnZen about, using an operation that returns a result and then ignoring it. To force the `map` lazy evaluation, I use an empty `deque` to consume it.