List problem

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

List problem

subhabangalore@gmail.com
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




Reply | Threaded
Open this post in threaded view
|

List problem

Lutz Horn-4
Him

Am 02.12.2012 um 16:03 schrieb subhabangalore at gmail.com:
> 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.

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

Lutz

--
This email is signed with a CAcert certificate. https://www.cacert.org/
Please do not send me Microsoft Office/Apple iWork documents.
Send OpenDocument instead! http://fsf.org/campaigns/opendocument/
https://duckduckgo.com/ | http://donttrack.us/ | http://dontbubble.us/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2728 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20121202/fae8e6a7/attachment.bin>

Reply | Threaded
Open this post in threaded view
|

List problem

Thomas Bach-2
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.


Reply | Threaded
Open this post in threaded view
|

List problem

subhabangalore@gmail.com
In reply to this post by Lutz Horn-4
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.


Reply | Threaded
Open this post in threaded view
|

List problem

Neil D. Cerutti
In reply to this post by Lutz Horn-4
On 2012-12-02, Thomas Bach <thbach at students.uni-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


Reply | Threaded
Open this post in threaded view
|

List problem

John Gordon-2
In reply to this post by subhabangalore@gmail.com
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