LING 408/508: Programming for Linguists Lecture 27 December 9 th
Class Inheritance
Higher order functions map(function,list) apply function to each member of the list in turn creating a transformed list
Higher order functions map(function,list) apply function to each member of the list in turn creating a transformed list inline anonymous function: lambda example: λx.x+x lambda x:x+x
Higher order functions reduce(function,list) apply 2-argument function from left to right 1 st argument will be cumulative value 2 nd argument is fresh argument from the list number of cannonballs in pyramid (Wikipedia):
Higher order functions filter(function,list) apply function to each member of the list collect those for which the function returns true
Standard Deviation Example textbook code seems problematic…
Median Median: – average of middle two if even number of elements – middle element of list if odd number of elements
Lists Comparisons: – default sort order: cmp(x,y) – returns -1 (x y)
Lists create a list of Student objects in variable data
Dictionaries Hash table: List: – delimiter: square brackets Dictionary: – delimiter: curly braces
Dictionaries
Word frequency table program: tokenization
Dictionaries Word frequency table program default = 0
Dictionaries Word frequency table program
Corpus Lead NYTimes article one year ago tomorrow:
Non-ASCII Corpus
wc.py for non- ascii ” regular expression convert and insert space for curly quotes, commas, single quotes, and periods not preceded by a capital letter sys.argv list holds command line filename and n most freq words
Results sys.argv[1] sys.argv[2] top 2 content words in the article
Adminstrivia TCEs are fully online (paper TCEs are history)