My Tech Notes
Python: remove dictionary items while iterating it
Delete the matching items based on the keys:
for k in dict.keys(): if k == 'yes': del dict[k]
Delete the matching items based on the values:
for k, v in dict.items(): if v == 3: del dict[k]
No comments:
Post a Comment
‹
›
Home
View web version
No comments:
Post a Comment