List problem
John Gordon
gordon at panix.com
Mon Dec 3 11:49:10 EST 2012
More information about the Python-list mailing list
Mon Dec 3 11:49:10 EST 2012
- Previous message (by thread): List problem
- Next message (by thread): Weird exception handling behavior -- late evaluation in except clause
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In <8c0a3ea9-2560-47eb-a9c7-3770e41fe7e1 at googlegroups.com> subhabangalore at gmail.com writes: > Dear Group, > I have a list of the following pattern, > [("''", "''"), ('Eastern', 'NNP'), ('Army', 'NNP'), ('Commander', 'NNP'), (= > 'Lt', 'NNP'), ('Gen', 'NNP'), ('Dalbir', 'NNP'), ('Singh', 'NNP'), ('Suhag'= > , 'NNP'), ('briefed', 'VBD'), ('the', 'DT'), ('Army', 'NNP'), ('chief', 'NN= > '), ('on', 'IN'), ('the', 'DT'), ('operational', 'JJ'), ('preparedness', 'N= > N'), ('and', 'CC'), ('the', 'DT'), ('security', 'NN'), ('scenario', 'NN'), = > ('in', 'IN'), ('the', 'DT'), ('eastern', 'NN'), ('region', 'NN'), (',', ','= > ), ("''", "''"), ('defence', 'NN'), ('spokesperson', 'NN'), ('Group', 'NNP'= > ), ('Capt', 'NNP'), ('T', 'NNP'), ('K', 'NNP'), ('Singha', 'NNP'), ('said',= > 'VBD'), ('here', 'RB')] > Now, as we see it has multiple VBD elements. > I want to recognize,count and index them all. That depends on exactly what you mean by 'reorganize' and 'index'. But here's a start: items = [("''", "''"), ('Eastern', 'NNP'), ('Army', 'NNP'), ('Commander', 'NNP'), ('Lt', 'NNP'), ('Gen', 'NNP'), ('Dalbir', 'NNP'), ('Singh', 'NNP'), ('Suhag' , 'NNP'), ('briefed', 'VBD'), ('the', 'DT'), ('Army', 'NNP'), ('chief', 'NN'), ('on', 'IN'), ('the', 'DT'), ('operational', 'JJ'), ('preparedness', 'NN'), ('and', 'CC'), ('the', 'DT'), ('security', 'NN'), ('scenario', 'NN'), ('in', 'IN'), ('the', 'DT'), ('eastern', 'NN'), ('region', 'NN'), (',', ','), ("''", "''"), ('defence', 'NN'), ('spokesperson', 'NN'), ('Group', 'NNP'), ('Capt', 'NNP'), ('T', 'NNP'), ('K', 'NNP'), ('Singha', 'NNP'), ('said', 'VBD'), ('here', 'RB')] vbds = [item[0] for item in items if item[1] == 'VBD'] print vbds
- Previous message (by thread): List problem
- Next message (by thread): Weird exception handling behavior -- late evaluation in except clause
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list