python count number of times the date has appeared

Posted by Rajeev on Stack Overflow See other posts from Stack Overflow or by Rajeev
Published on 2012-12-02T10:20:29Z Indexed on 2012/12/02 11:04 UTC
Read the original article Hit count: 152

Filed under:

From the following array,how to count the dates for the number of times it has occured in the array.The output should be in the following format [date,count]

   new_dates =  [['2012-12-02', 14],['2012-12-03',2],....]

Input:

  dates = [['2012-12-02', 17], ['2012-12-01', 5], ['2012-12-02', 15], ['2012-12-02', 8], ['2012-12-02', 17], ['2012-12-02', 15], ['2012-12-11', 6], ['2012-12-02', 1], ['2012-12-02', 9], ['2012-12-02', 11], ['2012-12-03', 13], ['2012-12-03', 10], ['2012-12-02', 18], ['2012-12-02', 11], ['2012-12-02', 12], ['2012-12-05', 14], ['2012-12-02', 3], ['2012-12-02', 6], ['2012-12-06', 10], ['2012-12-07', 0], ['2012-12-08', 3], ['2012-12-09', 12], ['2012-12-02', 6]]

© Stack Overflow or respective owner

Related posts about python