I have the following function that is being used to return results for an API. What I want to do is show self.ced_url within sources as well. What I'm not understanding is how to add that dictionary key/value into the list comprehension.
def to_dict(self):
ret = {
"event_data_url": self.ced_url,
"sources": [s.to_dict() for s in self.sources]
}
return ret
EDIT: Incorporated Kaya's suggestion to use
ret['sources'].append(self.ced_url)Assuming you want
ced_urlas part ofsourcesinret: