""" This functions helps to interpreting a list of integers. """

def make_intervals(list):
  """   Sort the list and changes e.g. 11,12,13 to  '11-13'
  (It is an interval.)
  It stores the no uniq numbers too."""
  intervals = []
  list.sort()
  index_of_the_first = 0
  for i in range(len(list) - 1): # i: indexes from zero to len(list)
	if list[i] + 1 == list[i+1] or list[i] == list[i+1]:
		continue
	#elif list[i] == list[i+1]: 
	#	not_uniq.append(  (list.count(list[i]), list[i])  )
	else:
		intervals.append( (list[index_of_the_first],list[i]) ) 
		index_of_the_first = i + 1
  # And now the last element:
  last_index = len(list) - 1
  intervals.append( (list[index_of_the_first],list[last_index]) )
  return intervals

def print_intervals(intervals):
  " It prints the intervals (e.g. 12-34) and single numbers. "
  for i in intervals:
	if i[0] == i[1]:
		print "%d," % i[0],
	else:
		print "%d-%d," % i,
  print

def search_not_uniq(list):
  # It makes a new list. It is as long as the 'list',
  # and all of the elements are '1' (number).
  not_uniq=[]
  for i in list:
	if list.count(i) != 1 and not_uniq.count(i) < 1:
		not_uniq.append(i)
  return not_uniq
	
def print_not_uniq(not_uniq,list):
  for i in not_uniq:
	print "You %d times have the %d-th exercise" % (list.count(i),i)
  


###########################################################
def test():
	" The test of the functions"
	a = [5,7,2,4,3,9,8,8,1,10,7,7,2,2,50,50,51,25,101,-2,-3,-4]
	a.sort()
	print a
	intervals= make_intervals(a)
	print intervals
	print_intervals(intervals)
	not_uniq=search_not_uniq(a)
	print not_uniq
	print_not_uniq(not_uniq,a)
