I have a dictionary with data similar to what is below
{'Bldg1':[('0', 'Sam'), ('0', 'John'), ('1', 'Tom'), ('2', 'Jane')], 'Bldg2' :[('0', 'Peter'), ('0', 'Dan'), ('1', 'Tom'), ('1', 'Jack'), ('3', 'Frank')]}
I am trying to combine tenants on the same floor of a building. Except for the Tenant, there is duplicate data like floor '0' in 'Blgd1' . I am trying take the duplicate data and combine the second value to look similar to the output below:
{'Bldg1':[('0', 'Sam - John'), ('1', 'Tom'), ('2', 'Jane')], 'Bldg2' :[('0', 'Peter - Dan'), ('1', 'Tom - Jack'), ('3', 'Frank')]}
I have been working with the function below and it will remove duplicate entries, but I am stuck moving forward. Is this even possible?
def get_tenants_bldg_floor(dct, building, floor):
unique_tenant_list = []
for k,v in dct.iteritems():
building = k
for item in v:
floor = item[0]
tenant = item[1]
ten_bldg_floor = tenant+', '+bldg_in_func+', '+floor_in_func
for v in k:
if ten_bldg_floor in unique_tenant_list:
print 1
else:
unique_tenant_list.append(ten_bldg_floor)
print 0
return unique_tenant_list
{building: {floor: [tenant, list]}}