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"}]

```
Maybe something like:

```
def remove_nulls(d):
    res = {}
    for k, v in d.items():
        if v == "NULL":
            continue
        if isinstance(v, dict):
            res[k] = remove_nulls(v)
        else:
            res[k] = v
    return res

print([remove_nulls(d) for d in lt])

```