title: Unable to create duplicate list from existing list using list comprehension with an if condition
body: <p>I have a sorted list with duplicate elements like</p>
  
  <pre><code>&gt;&gt;&gt; randList = [1, 2, 2, 3, 4, 4, 5]
  &gt;&gt;&gt; randList
  [1, 2, 2, 3, 4, 4, 5]
  </code></pre>
  
  <p>I need to create a list that removes the adjacent duplicate elements. I can do it like:</p>
  
  <pre><code>&gt;&gt;&gt;&gt; dupList = []
       for num in nums:
         if num not in dupList:
           dupList.append(num)
  </code></pre>
  
  <p>But I want to do it with list comprehension. I tried the following code:</p>
  
  <pre><code>&gt;&gt;&gt; newList = []
  &gt;&gt;&gt; newList = [num for num in randList if num not in newList]
  </code></pre>
  
  <p>But I get the result like the if condition isn't working.</p>
  
  <pre><code>&gt;&gt;&gt; newList
  [1, 2, 2, 3, 4, 4, 5]
  </code></pre>
  
  <p>Any help would be appreciated. 
  Thanks!! </p>
  
  <p>Edit 1: The wording of the question does seem to be confusing given the data I have provided. The for loop that I am using will remove <em>all</em> duplicates but since I am sorting the list beforehand, that shouldn't a problem when removing adjacent duplicates.</p>