Python Filter List if Match/Exist in a List

July 24, 2018
query_params = {'city': 'kuala lumpur', 'district': 'cheras', 'street': 'jalan melawati'}

# filter query_params to contain district and city only
query_params = { _allow_key: query_params[_allow_key] for _allow_key in ['district', 'city'] if _allow_key in query_params }
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.