title: Learn Python the Hard Way, Exercise 48
body: <p>I've been all day trying to solve the <code>test_errors()</code> function in "<a href="http://learnpythonthehardway.org/book/ex48.html" rel="nofollow">Exercise 48: Advanced User Input</a>" of the book <a href="http://learnpythonthehardway.org/book/" rel="nofollow">Learn Python The Hard Way</a>. </p>
  
  <p><code>assert_equal()</code>, a function in the tests asks me for the tuples in order and I haven't been able to code it that way.</p>
  
  <p>My loops always returns first the nouns and last the error tuples, I don't know how to break the loop so it starts again but with the right values to continue or whatever is necessary to sort this tuples in the order they should be. </p>
  
  <p>Here's the code:</p>
  
  <pre><code>class Lexicon(object):
  
  def scan(self, stringo):
      vocabulary = [[('direction', 'north'), ('direction', 'south'), ('direction',     'east'), ('direction', 'west')],
                      [('verb', 'go'), ('verb', 'kill'), ('verb', 'eat')],
                      [('stop', 'the'), ('stop', 'in'), ('stop', 'of')],
                      [('noun', 'bear'), ('noun', 'princess')],    # Remember numbers
                      [('error', 'ASDFADFASDF'), ('error', 'IAS')],
                      [('number', '1234'), ('number','3'), ('number', '91234')]]
  
      self.stringo = stringo
      got_word = ''
      value = []
      rompe = self.stringo.split() #split rompe en los espacios
  
      for asigna in vocabulary: 
          for encuentra in asigna:          
              if encuentra[1]  in rompe:
                  value.append(encuentra)
  
      return value   
  
  eLexicon = Lexicon()
  
  
  from nose.tools import *
  from ex48.ex48 import eLexicon 
  
  def test_directions():
      assert_equal(eLexicon.scan("north"), [('direction', 'north')])
      result = eLexicon.scan("north south east")
      assert_equal(result, [('direction', 'north'),
                    ('direction', 'south'),
                ('direction', 'east')])
  
  def test_verbs():
      assert_equal(eLexicon.scan("go"), [('verb', 'go')])
      result = eLexicon.scan("go kill eat")
      assert_equal(result, [('verb', 'go'),
                    ('verb', 'kill'),
                    ('verb', 'eat')])
  
  def test_stops():
      assert_equal(eLexicon.scan("the"), [('stop', 'the')])
      result = eLexicon.scan("the in of")
      assert_equal(result, [('stop', 'the'),
                    ('stop', 'in'),
                    ('stop', 'of')])
  
  def test_nouns():
      assert_equal(eLexicon.scan("bear"), [('noun', 'bear')])
      result = eLexicon.scan("bear princess")
      assert_equal(result, [('noun', 'bear'),
                    ('noun', 'princess')])
  
  #def test_numbers():
  #   assert_equal(lexicon.scan("1234"), [('number', 1234)])
  #   result = lexicon.scan("3 91234")
  #   assert_equal(result, [('number', 3),
  #                 ('number', 91234)])
  
  def test_errors():
      assert_equal(eLexicon.scan("ASDFADFASDF"), [('error', 'ASDFADFASDF')])
      result = eLexicon.scan("bear IAS princess")
      assert_equal(result, [('noun', 'bear'),
                    ('error', 'IAS'),
                    ('noun', 'princess')])
  
  ======================================================================
  FAIL: tests.ex48_tests.test_errors
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
      self.test(*self.arg)
    File "/home/totoro/Desktop/Python/projects/ex48/tests/ex48_tests.py", line 43, in         test_errors
      ('noun', 'princess')])
  AssertionError: Lists differ: [('noun', 'bear'), ('noun', 'p... != [('noun', 'bear'),     ('error', '...
  
  First differing element 1:
  ('noun', 'princess')
  ('error', 'IAS')
  
  - [('noun', 'bear'), ('noun', 'princess'), ('error', 'IAS')]
  + [('noun', 'bear'), ('error', 'IAS'), ('noun', 'princess')]
  
  ----------------------------------------------------------------------
  Ran 5 tests in 0.006s
  </code></pre>
  
  <p>Many thanks in advance for taking the time.</p>