I need the most efficient way to delete few items from the dictionary, RIght now, Im using for stmt as given below..Thinking the same thing should be accomplished in few lines.
for eachitem in dicta:
del eachitem['NAME']
del eachitem['STATE']
del eachitem['COUNTRY']
del eachitem['REGION']
del eachitem['LNAME']
dicta = [{'name','Bob','STATE':'VA','COUNTRY':'US','REGION':'MIDWEST','LNAME':'Brian',Salary:6000}]
I want only the salary item in the dictionary once its deleted.
Any inputs are appreciated.
I suppose you could use:
Or, if you only want 1 key:
This does everything in place which I assume you want — Otherwise, you can do it out of place simply by: