Package matcher
Description
def packaging(items):
""":items: List of items ["Game", "Game", "Blue"]
"""
max_map = {
"M": {
"Cam": 1
},
"L": {
"Cam": 2,
"Game": 2,
"Blue": 1
}
}
item_map = {}
for item in items:
if item in item_map:
item_map[item] += 1
else:
item_map[item] = 1
output = []
print(item_map)
for item in item_map:
num = item_map[item]
l_box = []
if item == "Cam":
m_box = []
while num > 0:
#first put in L
print(num)
while num >= max_map['L']['Cam']:
print('{} {}'.format(num, l_box))
if len(l_box) == max_map['L']['Cam']:
output.append('L: {}'.format(l_box))
l_box = []
else:
l_box.append(item)
num -= 1
if 0 < len(l_box) <2:
if num > 0:
l_box.append(item)
num -= 1
output.append('L: {}'.format(l_box))
else:
output.append('L: {}'.format(l_box))
# put remainder in M boxes
if num > 0:
output.append('M: {}'.format([item]))
num -= 1
else:
while num > 0:
print(num)
if len(l_box) >= max_map['L'][item]:
output.append('L: {}'.format(l_box))
l_box = []
else:
l_box.append(item)
num -= 1
if len(l_box) > 0:
output.append('L: {}'.format(l_box))
return outputIs this HArd, medium or easy problem?