2. Language Processing and Python: Lists and Word Frequencies.
Before Class (using python)
- Make a list of the words one two three o'clock four o'clock rock
- Pick out the first word as a string
- Pick out the first word as a list
- Pick out the last word as a string
- Show how many words there are in the list
- Transform the list into a new list that only has numbers in it
take as many steps as you need
- Count how many times o'clock appears in the list
- you can access items in lists: list1, list1[-1], ...
- you can access sublists using slices: list1[first:last:step]
- there are many things you can do to lists
- similarly with strings and sets
- string → list: 'string'.split()
- list → string: ', '.join(['string', 'thing'])
- nltk defines frequency distributions: FreqDist()
- list comprehensions are powerful: [w for w in V if p(w)]
HG2051: Language and the Computer Francis Bond.