How can I return a subset of the data
dictionary with dict comprehension?
for example
from urllib.parse import urlencode, urlparse
data = [{"id": 123, "description": "big one", "productId": 1}, {"id":124, "description": "medium one", "productId": 2}, {"id": 125, "description": "small one", "productId": 3}]
url = urlparse("https://example.api.com/")
for elem in data:
query = urlencode(
query={"description": elem.get("description"), "productId": elem.get("productId")}
)
path = f"v1/product/{elem['id']}"
newurl = url._replace(path=path, query=query)
logger.debug(newurl.geturl())