title: Remove adjacent duplicate elements from a list
body: <p>Google Python Class | List Exercise - </p>
  
  <blockquote>
    <p>Given a list of numbers, return a list where
    all adjacent == elements have been reduced to a single element,
    so [1, 2, 2, 3] returns [1, 2, 3]. You may create a new list or
    modify the passed in list.</p>
  </blockquote>
  
  <p>My solution using a new list is -   </p>
  
  <pre><code>def remove_adjacent(nums):
    a = []
    for item in nums:
      if len(a):
        if a[-1] != item:
          a.append(item)
      else: a.append(item)        
    return a
  </code></pre>
  
  <p>The question even suggests that it could be done by modifying the passed in list. However, the python documentation warned against modifying elements while iterating a list using the for loop. </p>
  
  <p>I am wondering what else can I try apart from iterating over the list, to get this done. I am not looking for the solution, but maybe a hint that can take me into a right direction.</p>
  
  <p><strong>UPDATE</strong> </p>
  
  <p>-updated the above code with suggested improvements.</p>
  
  <p>-tried the following with a while loop using suggested hints - </p>
  
  <pre><code>def remove_adjacent(nums):
    i = 1
    while i &lt; len(nums):    
      if nums[i] == nums[i-1]:
        nums.pop(i)
        i -= 1  
      i += 1
    return nums
  </code></pre>