Beispiel #1
0
def decode_rule(rule):
    idx = rule.index(BAGS_CONTAINED)
    color = rule[0:idx].strip()
    b = Bag(color)
    if rule.endswith('no other bags.') == False:
        contains = rule[idx + len(BAGS_CONTAINED):].strip().split(',')
        for contain in contains:
            c, n = decode_sub_colors(contain.strip())
            b.add_contained_bag(c, n)
    return b