title: Selecting objects
body: <p>I have created an Atom object as follows:</p>
  
  <pre><code>class Atom(object):
      def __init__(self, symbol, x, y, z)
          self.symbol = symbol
          self.position = (x, y, z)
  </code></pre>
  
  <p>and a <code>Selection</code> class that contains atoms selected by some criteria:</p>
  
  <pre><code>class Selection(object):
      def __init__(self, a_system, atom_list=[]):
          for atom in a_system:
              atom_list.append(atom)
          self.atom_list = atom_list
  
      def by_symbol(self, symbol):
          r_list = []
          for atom in self.atom_list:
              if atom.symbol is symbol:
                  r_list.append(atom)
          self.atom_list = r_list
  
      def by_zrange(self, zmin, zmax):
          r_list = []
          for atom in self.atom_list:
              pos = atom.position[2]
              if pos &gt; zmin and pos &lt; zmax:
                  r_list.append(atom)
          self.atom_list = r_list
  </code></pre>
  
  <p>So as you can see I can say for example:</p>
  
  <pre><code># my_system is a list of atoms objects
  group = Selection(my_system)
  </code></pre>
  
  <p>and then say:</p>
  
  <pre><code>group.by_symbol('H')
  </code></pre>
  
  <p>and I'll have in object <code>group</code> all hydrogen atoms. Then if I do:</p>
  
  <pre><code>group.by_zrange(1, 2)
  </code></pre>
  
  <p>and I'll have in object <code>group</code> all hydrogen atoms which have z-coordinate between 1 and 2.</p>
  
  <p>I have other selections criteria but in general they have all the same structure, to know:</p>
  
  <pre><code>r_list = []
  for atom in self.atom_list:
      # Some criteria here
          r_list.append(atom)
  self.atom_list = r_list
  </code></pre>
  
  <p>So the question is: is there something I can do in order to avoid writing the above structure for each selection criteria?</p>
  
  <p>If you know there is a simpler way to accomplish my purpose I'll be glad to hear it.</p>