def map_sequence(seq, sequence_map, unk_item_id):
    """ Transform a splitted sequence of items into another sequence of items
        according to the rules encoded in the dict item2id
       seq: iterable
       sequence_map: dict
       unk_item_id: int"""

    item_ids = []
    for item in seq:
        item_id = sequence_map.get(item, unk_item_id)
        item_ids.append(item_id)
    return item_ids