Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103427
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-02-23 20:04 -0800 |
| Message-ID | <f0b9a2c6-1db4-4614-9221-585d3438c68f@googlegroups.com> (permalink) |
| Subject | How may I change values in tuples of list of lists? |
| From | subhabangalore@gmail.com |
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'and', 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.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
How may I change values in tuples of list of lists? subhabangalore@gmail.com - 2016-02-23 20:04 -0800 Re: How may I change values in tuples of list of lists? Ben Finney <ben+python@benfinney.id.au> - 2016-02-24 16:34 +1100
csiph-web