# -*- coding: utf-8 -*- ####ID histogram #### Exercise: #### #### Write a python function #### #### histogram(L) #### #### where L is a list of integers. The function must return a dictionary whose keys will be precisely the integers #### that appear in L, once each. The value of each key shall be the number of times the key appears in L. If the #### list L is empty then so must be the dictionary returned. #### #### For example, if L = [-1, 1, 0, 1, 2, -1] then the result will be the dictionary {-1: 2, 1: 2, 0: 1, 2: 1}. #### #### Write your code only between the the two lines marked START and STOP below. Do not alter any of the other lines. #### #### To run your program, stored in the file user.py, you give the command #### #### python user.py #### #### To check your program with the tester you give the command #### #### python tester.py #### #### or #### #### python tester.py filename.py #### #### if your program has been stored in filename.py. L = input("Please give a list of integers (Python style): ") #### Assumptions: #### #### At this point the list L has been given. #### #### Requirements: #### #### The function histogram() that you must fill in below must compute what is described above. ############################################################################# #### You must not give any print or input functions in your code below. ############################################################################# #### Do not change anything down to the next line. ####START You write your code after this line. def histogram(L): D = {} for k in L: if k in D: D[k] += 1 else: D[k] = 1 return D ####STOP Do not change anything on this line or below. print "histogram(%r) = %r" % (L, histogram(L))