def topk(l, k, key=lambda x: x):
    """Returns a sublist with the top k elements from a givenlist. Accepts key"""
    idx, _ = zip(*sorted(enumerate(l), key = lambda x: key(x[1]), 
                         reverse=True))
    return [l[i] for i in idx[0:k]]