new_contents: # A. match_ends
  def match_ends(words):
      n=len (words)
      i=0
      count=0
      while i<n:
          if len(words[i])>=2 and words[i][0]==words[i][-1]:
              count = count+1
          i = i+1
      return count
  
  # B. front_x
  def front_x(words):
      s=[]
      s1=[]
      for i in words:
          if i.startswith('x'):
              s.append(i)
          else:
              s1.append(i)
      s.sort()
      s1.sort()
      return s+s1
  
  # C. sort_last
  def last (a):
      return a[-1]
  
  def sort_last(tuples):
      return sorted(tuples, key=last)
  
  def test(got, expected):
    if got == expected:
      prefix = ' OK '
    else:
      prefix = '  X '
    print ('%s got: %s expected: %s' % (prefix, repr(got), repr(expected)))
  
  def main():
    print ('match_ends')
    test(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3)
    test(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2)
    test(match_ends(['aaa', 'be', 'abc', 'hello']), 1)
  
    print
    print ('front_x')
    test(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']),
         ['xaa', 'xzz', 'axx', 'bbb', 'ccc'])
    test(front_x(['ccc', 'bbb', 'aaa', 'xcc', 'xaa']),
         ['xaa', 'xcc', 'aaa', 'bbb', 'ccc'])
    test(front_x(['mix', 'xyz', 'apple', 'xanadu', 'aardvark']),
         ['xanadu', 'xyz', 'aardvark', 'apple', 'mix'])
  
         
    print
    print ('sort_last')
    test(sort_last([(1, 3), (3, 2), (2, 1)]),
         [(2, 1), (3, 2), (1, 3)])
    test(sort_last([(2, 3), (1, 2), (3, 1)]),
         [(3, 1), (1, 2), (2, 3)])
    test(sort_last([(1, 7), (1, 3), (3, 4, 5), (2, 2)]),
         [(2, 2), (1, 3), (3, 4, 5), (1, 7)])
  
  
  if __name__ == '__main__':
    main()
  
subject: Create list1.py