-4
Мой сценарий таков:Сбор значения из списка Обновление словаря
pic_from_list = ['best', 'good', 'ok']
dict_list = [{id = "1", food_source : "this food;is;good"}, {id = "2", food_source : "this food;is;ok"}, {id = "3", food_source : "this food is the best"}, {id = "4", food_source : none}, {id = "5", food_source : "no source"}]
мой код выглядит так:
for item in dict_list:
idt = item['id']
#print(idt)
source = item['source']
#print(source)
words = re.split(r'[.|;]+', str(source))
#print(words)
class_type = [i.strip() for i in words if i in pic_from_list]
#print(class_type)
if len(class_type) ==0:
if idt not in new_dict.values():
new_dict.update({'id': idt , 'food_class': 'none'})
dict_list.append(new_dict)
else:
pass
elif:
if idt not in new_dict.values():
new_dict.update({'id': idt , 'food_class': 'none'})
dict_list.append(new_dict)
else:
pass
print(dict_list[:4])
, который дает мне неправильный ввод, как:
[{'id':1, food_class:'none'}, {'id':1, food_class:'good'}, {'id':1, food_class:'ok'}..]
Пожалуйста, открепите свой код. – hashcode55
Пожалуйста, сократите это до [mcve] и объясните, что вы ожидали вместо этого. – jonrsharpe