List problem
John Gordon
gordon at panix.com
Mon Dec 3 11:49:10 EST 2012
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
More information about the Python-list
mailing list