# Frequency of elements in a list

I've got a list in the format of list={{a,1},{a,1},{b,1},{c,1},{b,1}} And I want it to "compress" into a list of pairs {element, frequency} such as this: {{a,2},{b,2},{c,1}}

I've come up with this (faulty) solution:

upravit[l_List] := {l[[1]], l[[2]] + 1}
compression[list_List] :=
list //. {a___, b_List, c_List, d___} /; c[[1]] == b[[1]] -> {a, upravit[b], d}

The problem is that I'm only checking elements that are next to each other, and so in the example, I'd end up with{{a,2},{b,1},{c,1},{b,1}}

Therefore, either I need to correct my code, or come up with an entirely different method (using similar methods thought, as this is a homework).

Thanks for any help!

Edit: as pointed out in the comments and answers, there is a function that easily does that. I should've specified that this should be done using the methods in my example only. Sorry!

-
you want to count based on just the letters? Something like: Tally[list[[All, 1]]]? –  Pinguin Dirk Jan 28 '13 at 11:30
Yes, that is exactly what I need, only using the methods I used, as using "tally" is against the purpose of the homework (that is to learn these methods) –  Dahn Jahn Jan 28 '13 at 11:33
ah ok - so maybe just Sort your list before running compression? (not sure what you are allowed to do and what not) –  Pinguin Dirk Jan 28 '13 at 11:36
I do not know why that didn't occur to me. Feel stupid now! Thanks for the help. –  Dahn Jahn Jan 28 '13 at 11:40
I don't really have a problem with (suitably tagged) homework questions being posted here, but isn't the point of homework that you figure these kinds of issues out for yourself? I can't quite understand what it accomplishes if someone else gives you the solution. Also, don't be surprised if your tutor is active on this site--there aren't that many venues like this for Mathematica users and a large fraction of the users here are academics. –  Oleksandr R. Jan 28 '13 at 12:43