Entries from 2013-05-27 to 1 day

Exercise: Chapter 3 (10-13)

10.The original one is: >>> sent = ['The', 'dog', 'gave', 'John', 'the', 'newspaper'] >>> result = [] >>> for word in sent: ... word_len = (word, len(word)) ... result.append(word_len) ... >>> result [('The', 3), ('dog', 3), ('gave', 4), (…

Exercise: Chapter 3 (7-9)

7. >>> nltk.re_show(r'\b(a|an|the)\b', 'brian a then an the man') brian {a} then {an} {the} man Usage of '\b' is the key point, I think.8. >>> import urllib >>> def cleantags(url): ... raw_contents = urllib.urlopen(url).read() ... return n…