Latest recipes by Johannes S http://code.activestate.com/recipes/users/4193888/new/2016-04-05T18:11:49-07:00ActiveState Code RecipesMerge unique items from multiple lists into a new list (Python) 2016-04-05T18:11:49-07:00Johannes Shttp://code.activestate.com/recipes/users/4193888/http://code.activestate.com/recipes/580634-merge-unique-items-from-multiple-lists-into-a-new-/ <p style="color: grey"> Python recipe 580634 by <a href="/recipes/users/4193888/">Johannes S</a> (<a href="/recipes/tags/lists/">lists</a>, <a href="/recipes/tags/merge/">merge</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/set/">set</a>). Revision 2. </p> <p>Suppose you have multiple lists. You want to print all unique items from the list. Now, what you could do is merge the lists into one_big_list (e.g., a + b +c), and then iterate over each item in one_big_list, etc. The solution proposed here gets this done faster and in one line of code. How? By using <strong>a python set</strong>. A python set is a dictionary that contains only keys (and no values). And dictionary keys are, by definition, unique. Hence, duplicate items are weeded out automatically. Once you have the set, you can easily convert it back into a list. As easy as that!</p>