function getParams(data) {
return {
id: data && data.uuid
}
}
So the above represents a common pattern in Javascript for accessing the items of an object.
What is the most commonly used equivalent practice in Python for accessing items of a dict?
Would it be like so?
def getParams(data):
params = {}
if data is not None and hasattr(data, "id"):
params["id"] = data["id"]
return params
If not, what is the best practice? Thanks.