def filterdict(itemfunc, dictionary):
    """
    Filters a dictionary like 'filter' filters a list. *itemfunc*
    should be a function which takes two parameter, a(key, value) pair
    and returns 1 if the pair should be in the new dictionary,
    0 otherwise.
    """
    return dict(filter(itemfunc, dictionary.items()))