List comprehensions Conversion
<p>i started learning Python recently and i am facing difficulty converting the below piece of code into a list comprehension:</p>

<pre><code>    list = []     #An empty List
    for key,value in defaultDict.items():#iterate through the default dict
        for i in defaultDict[key]:#iterate through the list in the defaultDict
            if i not in list:#If the item in the list is not present in the main list
                list.append(i)#append it
</code></pre>

<p>Is it possible for me to even do it??Any help with this is much appreciated.</p>

<p>Very straightforward: use a nested list comprehension to get all <code>i</code>s and a set to remove duplicates.</p>

<pre><code>list(set([item for __, value in defaultDict.items() for item in value]))
</code></pre>

<p>Let's break it down:</p>

<ul>
<li><code>[item for key,value in defaultDict.items() for item in value]</code> is a <a href="http://stackoverflow.com/questions/18072759/python-nested-list-comprehension">nested list comprehension</a>.</li>
<li><code>set(...)</code> will remove all duplicates - the equivalent of <code>if i not in list: list.append(i)</code> logic you have</li>
<li><code>list(set(...))</code> will convert the set back to a list for you.</li>
</ul>

python list list-comprehension defaultdict