Simple Python Exercises

http://ideone.com/ can be used to write the code.

Exercise 1

Create a sorted list from the following list of 2-tuples by the second element of each tuple. The original list should be left intact. (5 minutes)

indata = [
  ('a', 0),
  ('b', 2),
  ('c', 1),
]

Exercise 2

Count the number of unique values in a list. (3 minutes)

import random
indata = [random.randrange(100) for it in xrange(20)]

Exercise 3

Clean up Python comments from a source file. (10 minutes)