python nltk 学习笔记(4) Writing Structured Programs

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')]


 
原文地址:https://www.cnblogs.com/wintor12/p/3622556.html