Hi 

I am trying to use the following set of tuples in list of lists. 
I am using a Python based library named, NLTK. 

>>> import nltk
>>> from nltk.corpus import brown as bn
>>> bt=bn.tagged_sents()
>>> bt_5=bt[:5]
>>> print bt
[[(u'The', u'AT'), (u'Fulton', u'NP-TL'), (u'County', u'NN-TL'), (u'Grand', 
u'JJ-TL'), (u'Jury', u'NN-TL'), (u'said', u'VBD'), (u'Friday', u'NR'), (u'an', 
u'AT'), (u'investigation', u'NN'), (u'of', u'IN'), (u"Atlanta's", u'NP$'), 
(u'recent', u'JJ'), (u'primary', u'NN'), (u'election', u'NN'), (u'produced', 
u'VBD'), (u'``', u'``'), (u'no', u'AT'), (u'evidence', u'NN'), (u"''", u"''"), 
(u'that', u'CS'), (u'any', u'DTI'), (u'irregularities', u'NNS'), (u'took', 
u'VBD'), (u'place', u'NN'), (u'.', u'.')], [(u'The', u'AT'), (u'jury', u'NN'), 
(u'further', u'RBR'), (u'said', u'VBD'), (u'in', u'IN'), (u'term-end', u'NN'), 
(u'presentments', u'NNS'), (u'that', u'CS'), (u'the', u'AT'), (u'City', 
u'NN-TL'), (u'Executive', u'JJ-TL'), (u'Committee', u'NN-TL'), (u',', u','), 
(u'which', u'WDT'), (u'had', u'HVD'), (u'over-all', u'JJ'), (u'charge', u'NN'), 
(u'of', u'IN'), (u'the', u'AT'), (u'election', u'NN'), (u',', u','), (u'``', 
u'``'), (u'deserves', u'VBZ'), (u'the', u'AT'), (u'praise', u'NN'), (u'an
 d', u'CC'), (u'thanks', u'NNS'), (u'of', u'IN'), (u'the', u'AT'), (u'City', 
u'NN-TL'), (u'of', u'IN-TL'), (u'Atlanta', u'NP-TL'), (u"''", u"''"), (u'for', 
u'IN'), (u'the', u'AT'), (u'manner', u'NN'), (u'in', u'IN'), (u'which', 
u'WDT'), (u'the', u'AT'), (u'election', u'NN'), (u'was', u'BEDZ'), 
(u'conducted', u'VBN'), (u'.', u'.')], ...]
>>> 

Now if I want to change the values of tags like 'AT', 'NP-TL', 'NN-TL', etc. to 
some arbitrary ones like XX,YY,ZZ and yet preserve total structure of tuples in 
list of lists, please suggest how may I do it. 

I donot think it is an NLTK issue, rather a Python issue. 
I am trying to access and change but using 
for i,j in enumerate(bt_5), etc. bit long stuff.

If any one may kindly suggest a smart line of code. 

I am using Python2.7.11 on MS-Windows-10. My NLTK version is 3.1

Thanks in advance.

Regards,
RP.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to