count

Dhananjay dhananjay.c.joshi at gmail.com
Wed Jul 8 02:10:59 EDT 2009


Dear all,

I have file as follows,however, tab seperated (not shown in following file):

     6       3       4.309726
     7       65     93.377388
     8       47     50.111952
     9       270   253.045923
     10     184    182.684670
     11     76     121.853455
     12     85     136.283470
     13     114    145.910662
     14     45      80.703013
     15     44      47.154646
     16     41      66.461339
     17     16      33.819488
     18     127     136.105455
     19     70      88.798681
     20     29      61.297823


I wanted to sort column 2 in assending order  and I read whole file in array
"data" and did the following:

data.sort(key = lambda fields:(fields[2]))

I have sorted column 2, however I want to count the numbers in the column 2.
i.e. I want to know, for example, how many repeates of say '3' (first row,
2nd column in above data) are there in column 2.

I could write seperate programme to get the result.s.

However, is there any way to count the numbers there itself while sorting in
column 2 ?


Thanking you in advance,


-- Dhananjay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090708/507f91f3/attachment.html>


More information about the Python-list mailing list