I have a list of tuples and want to turn this list into a dictionary. However, the tuples can be larger than 2 and not the same size. I would like the first element of each tuple to be the key and the rest to be stored as a array for the value.
l = [(1,'a','b'),(2,'c'),(3,'d','e','f')]
Just doing d=dict(l)
doesn't work (didn't really expect it to). I would like to use a list comprehension along of the lines of d = dict([(k,v) for k,v in arr])
but allow for v of arbitrary size.
d = dict( (v[0], v[1:]) for v in arr )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With