Home > Net >  Delete a Specific values from a list
Delete a Specific values from a list

Time:12-22

I have an intermediate list in the following format

input = [{'EmpId': '00030010-0010-0000-0000-000000000144', 'Stack': 'Java', 'Code': 2214}, {'EmpId': '00030010-0010-0000-0000-000000000198', 'Stack ': '.net', 'Code': 1494}, {'EmpId': '00030010-0010-0000-0000-000000000121', 'Stack': 'Ruby', 'Code': 1112}]

I need to delete all the occurrences of 'Code'

expected output = [{'EmpId': '00030010-0010-0000-0000-000000000144', 'Stack': 'Java'}, {'EmpId': '00030010-0010-0000-0000-000000000198', 'Stack ': '.net'}, {'EmpId': '00030010-0010-0000-0000-000000000121', 'Stack': 'Ruby'}]

Please assist.

CodePudding user response:

This line of code should work:

for i in input:
    i.pop("Code")

CodePudding user response:

This might help

dd = [i.pop("Code") for i in input]
print(input)

    [{'EmpId': '00030010-0010-0000-0000-000000000144', 'Stack': 'Java'}, {'EmpId': '00030010-0010-0000-0000-000000000198', 'Stack ': '.net'}, {'EmpId': '00030010-0010-0000-0000-000000000121', 'Stack': 'Ruby'}]
  • Related