-2

Using Python 3, I'm trying to figure out how I can remove the key and value pairs for "BasicPay" and "TotalPay".

 d = {
    "PersonDetail": [
        {"EmployeeNumber": "123", "ID": 212, "BasicPay": 0.0000, "TotalPay": 0.0000},
        {"EmployeeNumber": "987", "ID": 213, "BasicPay": 0.0000, "TotalPay": 0.0000}
        ]
    }

I'm going round in circles at the moment, any pointers to get me going would be appreciated!

C8102E
  • 1
  • 1

1 Answers1

0

This should work. A for loop to go through each element.

d = {
    "PersonDetail": [
        {"EmployeeNumber": "123", "ID": 212, "BasicPay": 0.0000, "TotalPay": 0.0000},
        {"EmployeeNumber": "987", "ID": 213, "BasicPay": 0.0000, "TotalPay": 0.0000}
        ]
    }

for employee in d["PersonDetail"]:
    employee.pop("BasicPay")
    employee.pop("TotalPay")

print(d)
JimmyCarlos
  • 1,934
  • 1
  • 10
  • 24