I have a two-items list which I need to process. Those items are retrieved from a database, so the are actually header: value pairs but they are unparsed. They are strings separated by tabs, so the list looks like this:
my_list = ['header1\theader2\theader3\theader4', 'val1\tval2\tval3\tval4']
I need to create dict from the key - value pairs. Currently I do it with list comprehension:
keys = [k.strip() for k in my_list[0].split('\t')]
vals = [v.strip() for v in my_list[1].split('\t')]
return dict(zip(keys, vals))
I think there might be a way doing that using dict comprehension instead, but I couldn't get how. Is it possible to do parse the list items and return a dictionary with a one-liner or a more pythonic way?