You have list of dictionaries not list of objects. We can join them together like this
print ", ".join(d["name"] for d in a)
d["name"] for d in a
is called a generator expression, str.join
will get the values from the generator expression one by one and join all of them with ,
in the middle.
But, if the list of dictionaries is too big then we can create a list of strings ourselves and pass it to the str.join
like this
print ", ".join([d["name"] for d in a])
Here, [d["name"] for d in a]
is called list comprehension, which iterates through a
and creates a new list with all the name
s and we pass that list to be joined with ,
.
I just noticed the discussion in the comments section. Please check this answer to know, why List Comprehension is better than GenExp in string joining.