Find top N values for field X based on field Y's value

I want to find the top N entries for a certain field based on the values of another field.

For example if N=3, we want the 3 best values for each entry:

Entry1 ||| 100
Entry1 ||| 95
Entry1 ||| 30
Entry1 ||| 80
Entry1 ||| 50
Entry2 ||| 40
Entry2 ||| 20
Entry2 ||| 10
Entry2 ||| 50
Entry2 ||| 30

would return

Entry1 ||| 100
Entry1 ||| 95
Entry1 ||| 80
Entry2 ||| 40
Entry2 ||| 50
Entry2 ||| 30

if you have Python

d={}
for line in open("file"):
    line=line.strip().split(" ||| ")
    d.setdefault(line[0],[])
    d[line[0]].append(line[-1])
for i,j in d.iteritems():
    for item in sorted(j,lambda x,y: int(y)-int(x))[:3]:
        print "%s ||| %s" %(i,item)

output

# ./test.py
Entry2 ||| 50
Entry2 ||| 40
Entry2 ||| 30
Entry1 ||| 100
Entry1 ||| 95
Entry1 ||| 80

show your code next time.