Let's say I have a list of dictionnaries call x. If I want to extract the keys and push them into a new list called y :
y = {k for d in x for k in d.keys()}
y = {k for k in chain(*x)}
Now I want to do the same operation with a function. As I don't know the name of the list of dict in advance, I was thinking of using *args
def formatting(*args):
return {k for d in args for k in d.keys()}
x_list = formatting(x)
But doing this return AttributeError: 'list' object has no attribute 'keys'
When I passing the real variable name in the function, it's working...
What is the correct way of passing list of dict into a function ?