<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def categorize(values, categories, default=None):
 """Maps discrete values to supplied categories. Replaces discrete values in input array with a fixed set of categories defined either as a list or dictionary. Args: values: Array of values to be categorized categories: List or dict of categories to map inputs to default: Default value to assign if value not in categories Returns: Array of categorized values """

    uniq_cats = list(unique_iterator(values))
    cats = []
    for c in values:
        if isinstance(categories, list):
            cat_ind = uniq_cats.index(c)
            if cat_ind < len(categories):
                cat = categories[cat_ind]
            else:
                cat = default
        else:
            cat = categories.get(c, default)
        cats.append(cat)
    return np.asarray(cats)