List problem

Neil Cerutti neilc at norwich.edu
Mon Dec 3 14:04:26 CET 2012


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



More information about the Python-list mailing list