Adding two asynchronous lists, into a dictionary
<p>I've always found Dictionaries to be an odd thing in python. I know it is just me i'm sure but I cant work out how to take two lists and add them to the dict. If both lists were mapable it wouldn't be a problem something like <code>dictionary = dict(zip(list1, list2))</code> would suffice. However, during each run the <code>list1</code> will always have one item and the <code>list2</code> could have multiple items or single item that I'd like as values.</p>

<p>How could I approach adding the key and potentially multiple values to it?</p>

<p>After some deliberation, Kasramvd's second option seems to work well for this scenario:</p>

<p><code>dictionary.setdefault(list1[0], []).append(list2)</code></p>

<p>Based on your comment all you need is assigning the second list as a value to only item of first list.</p>

<pre><code>d = {}
d[list1[0]] = list2
</code></pre>

<p>And if you want to preserve the values for duplicate keys you can use <code>dict.setdefault()</code> in order to create value of list of list for duplicate keys.</p>

<pre><code>d = {}
d.setdefault(list1[0], []).append(list2)
</code></pre>

python dictionary