Velocity Reviews > List problem

# List problem

subhabangalore@gmail.com
Guest
Posts: n/a

 12-02-2012
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

Thomas Bach
Guest
Posts: n/a

 12-02-2012
On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote:
>
> 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.

subhabangalore@gmail.com
Guest
Posts: n/a

 12-02-2012
On Sunday, December 2, 2012 9:29:22 PM UTC+5:30, Thomas Bach wrote:
> On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote:
>
> >

>
> > 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.

subhabangalore@gmail.com
Guest
Posts: n/a

 12-02-2012
On Sunday, December 2, 2012 9:29:22 PM UTC+5:30, Thomas Bach wrote:
> On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote:
>
> >

>
> > 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.

Neil Cerutti
Guest
Posts: n/a

 12-03-2012
On 2012-12-02, Thomas Bach <(E-Mail Removed)-mainz.de> wrote:
> On Sun, Dec 02, 2012 at 04:16:01PM +0100, Lutz Horn wrote:
>>
>> 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.

To also index them:

vbdix = [i for i, a in emumerate(l) if a[1] == 'VBD']
vbdno = len(indices)

--
Neil Cerutti

John Gordon
Guest
Posts: n/a

 12-03-2012
In <(E-Mail Removed)> http://www.velocityreviews.com/forums/(E-Mail Removed) 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