code: def train(nr_iter, examples):
      '''Return an averaged perceptron model trained on ``examples`` for
      ``nr_iter`` iterations.
      '''
      model = AveragedPerceptron()
      for i in range(nr_iter):
          random.shuffle(examples)
          for features, class_ in examples:
              scores = model.predict(features)
              guess, score = max(scores.items(), key=lambda i: i[1])
              if guess != class_:
                  model.update(class_, guess, features)
      model.average_weights()
      return modef train(nr_iter, examples):
      '''Return an averaged perceptron model trained on ``examples`` for
      ``nr_iter`` iterations.
      '''
      model = AveragedPerceptron()
      for i in range(nr_iter):
          random.shuffle(examples)
          for features, class_ in examples:
              scores = model.predict(features)
              guess, score = max(scores.items(), key=lambda i: i[1])
              if guess != class_:
                  model.update(class_, guess, features)
      model.average_weights()
      return model
docs: Return an averaged perceptron model trained on ``examples`` for
      ``nr_iter`` iterations.