Counting

Andy andy.rockford at gmail.com
Mon Apr 30 03:26:24 CEST 2007


James -

I pretty doubt about this - "c = line.count(k)" You might wanna
recheck on that.
------------------------------------------------
I think it would be obvious how to write this:

for i,line in enumerate(linelist):
   line = line.split()
   for k in line:
     if keyword.iskeyword(k):
       c = line.count(k)
       total += line.count(k)
       print "Line #%d has %d keywords." % (i+1, c)
       break

print "Total keyords are: %d" % total


>
> I think it would be obvious how to write this:
>
> for i,line in enumerate(linelist):
>    line = line.split()
>    for k in line:
>      if keyword.iskeyword(k):
>        c = line.count(k)
>        total += line.count(k)
>        print "Line #%d has %d keywords." % (i+1, c)
>        break
>
> print "Total keyords are: %d" % total





More information about the Python-list mailing list