[Solved] How create dict from lists of list? [closed]
[ad_1] Assuming that you want to name your keys as key1, key2.. and so on when a key is not found: l = [[‘a’,1], [‘b’,2], [3], [‘d’,4]] d = {} i = 1 for x in l: try: d[x[0]] = x[1] except IndexError: d[‘key’+str(i)] = x[0] i += 1 print(d) Output: {‘a’: 1, ‘b’: 2, … Read more