List problem

S

subhabangalore

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

Now, as we see it has multiple VBD elements.
I want to recognize,count and index them all.

If any one can kindly suggest.

Regards,
Subhabrata
 
S

subhabangalore

len([x for x in l if x[1] == 'VBD'])



Another way is



sum(1 for x in l if x[1] == 'VBD')



which saves the list creation.



Regards,

Thomas.

Thanks. After I posted I got a solution as,
[x for x, y in enumerate(chunk_word) if "/VB" in y]
but you are smarter.
Thanks.
Regards,
Subhabrata.
 
S

subhabangalore

len([x for x in l if x[1] == 'VBD'])



Another way is



sum(1 for x in l if x[1] == 'VBD')



which saves the list creation.



Regards,

Thomas.

Thanks. After I posted I got a solution as,
[x for x, y in enumerate(chunk_word) if "/VB" in y]
but you are smarter.
Thanks.
Regards,
Subhabrata.
 
J

John Gordon

In said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top