{"id":876,"date":"2014-09-22T19:00:00","date_gmt":"2014-09-22T19:00:00","guid":{"rendered":"https:\/\/fir3netwp.gmsrrpobkbd.com\/2014\/09\/22\/python-filtering-a-dictionary-against-a-list-of-values\/"},"modified":"2021-07-24T17:07:28","modified_gmt":"2021-07-24T17:07:28","slug":"python-filtering-a-dictionary-against-a-list-of-values","status":"publish","type":"post","link":"https:\/\/www.fir3net.com\/Programming\/Python\/python-filtering-a-dictionary-against-a-list-of-values.html","title":{"rendered":"Python – Filtering a dictionary against a list of values"},"content":{"rendered":"
This short Python snippet shows you how to filter a dictionary against a list of values via the use of a list comprehension.<\/p>\n
>>> d = {\"apples\":1,\"bananas\":2,\"pears\":3}
>>> {x:y for x,y in d.iteritems() if x in [\"apples\",\"pears\"]}
{'apples': 1, 'pears': 3}<\/pre>\n","protected":false},"excerpt":{"rendered":"This short Python snippet shows you how to filter a dictionary against a list of values via the use of a list comprehension. >>> d = {“apples”:1,”bananas”:2,”pears”:3} >>> {x:y for x,y in d.iteritems() if x in [“apples”,”pears”]}{‘apples’: 1, ‘pears’: 3}<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"yoast_head":"\n
Python - Filtering a dictionary against a list of values - Fir3net<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n