def filterdict(origdict, keyset):
    """returns the subset of origdict containing only the keys in keyset and their corresponding values """
    newdict = {}
    # this cunningly works with cidict (case-insensitive dictionary class)
    # since we just check if key in origdict, not the reverse...
    # the keys are those from keyset, not origdict
    for key in keyset:
        if key in origdict:
            newdict[key] = origdict[key]
    return newdict