import pickle


def serialize_for_index(value, serializer=pickle):
    """Serializes value for storing it in the index table.
    If value is an iterable we will convert it to tuple because thats how we
    store values for compound indexes.
    """
    if isinstance(value, (list, set, dict)):
        value = tuple(value)
    return serializer.dumps(value)