title: Code shortening membership check in set
body: <p>I have a set that contains all the items I want to print out. However, the output should be different based on whatever else is in the set. Here is an example:</p>
  
  <pre><code>for i in set(range(10))-{a*b for a in range(2,5)for b in range(2,4)}:
  print i if i-1 not in set(range(10))-{a*b for a in range(2,5)for b in range(2,4)}and i+1 not in set(range(10))-{a*b for a in range(2,5)for b in range(2,4)}else `i`+"!"
  
  #For readability purposes, here is the unshortened code
  
  originalNumbers = set(range(10))
  numbersToRemove = set([a*b for a in range(2,5) for b in range(2,4)])
  finalList = originalNumbers - numbersToRemove
  
  for number in finalList:
      if number - 1 in finalList or number + 1 in finalList:
          print str(number) + "!"
      else:
          print number
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>0!
  1!
  2!
  3!
  5
  7
  </code></pre>
  
  <p>which is correct. Is there a shorter way I can do this without having to copy the original set again and still maintain a code that can be written in one line/statement?</p>
  
  <p><strong>Note:</strong>
  The set doesn't have to be the one I specified, I just used that as an example.</p>