suppose I have a dictionary
kwargs = {'key1': 1,
'key2': 2,
'key3list': [1,2,3,4]}
Where one of the values of any of the keys could be a list of integers, while the others would just be any object, in this case, an integer. I want to, in a single line (or in a couple at most) , put all the values of the keys into one tuple, unpacking all possible lists. Notice that by how the dictionary kwargs
is constructed, keys having a list will have the key ending with 'list'.
I came up with the following:
a = tuple(
[kwargs[key] if not key.endswith('list') else *kwargs[key] for key in kwargs.keys()]
)
However I get the error that I cannot unpack *kwargs[key]
here..
How could I fix this?