python - Adding two asynchronous lists, into a dictionary -


i've found dictionaries odd thing in python. know me i'm sure cant work out how take 2 lists , add them dict. if both lists mapable wouldn't problem dictionary = dict(zip(list1, list2)) suffice. however, during each run list1 have 1 item , list2 have multiple items or single item i'd values.

how approach adding key , potentially multiple values it?

after deliberation, kasramvd's second option seems work scenario:

dictionary.setdefault(list1[0], []).append(list2)

based on comment need assigning second list value item of first list.

d = {} d[list1[0]] = list2 

and if want preserve values duplicate keys can use dict.setdefault() in order create value of list of list duplicate keys.

d = {} d.setdefault(list1[0], []).append(list2) 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -