简体   繁体   中英

remove certain key from a dictionary in python?

I have a list contains dictionaries

[{'item1':xxx, 'item2':xxx}, {'item1':xxx, 'item2':xxx}]

I want to remove all 'item1' so the list becomes:

['item2':xxx}, {'item2':xxx}]

What is the shortest syntax I could use? I know you can loop it through using for ...but I am looking for the simplest syntax! Thanks!

The simplest syntax is a for loop.

for D in L:
  del D['item1']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM