python nltk 学习笔记(4) Writing Structured Programs
Posted on 2014-03-25 10:24 wintor12 阅读(135) 评论(0) 编辑 收藏 举报In particular, the "value" of a structured object such as a list is actually just a reference to the object.
>>> foo = ['Monty', 'Python'] >>> bar = foo >>> foo[1] = 'Bodkin' >>> bar ['Monty', 'Bodkin']
for item in set(s).difference(t) //iterate over elements of s not in t
>>> words = ['I', 'turned', 'off', 'the', 'spectroroute'] >>> tags = ['noun', 'verb', 'prep', 'det', 'noun'] >>> zip(words, tags) [('I', 'noun'), ('turned', 'verb'), ('off', 'prep'), ('the', 'det'), ('spectroroute', 'noun')] >>> list(enumerate(words)) [(0, 'I'), (1, 'turned'), (2, 'off'), (3, 'the'), (4, 'spectroroute')]