将设置值分配给字典

时间:2016-06-24 11:01:38

标签: python list dictionary set

我的列表company_list_present包含重复值,看起来像[u'SOUTH ASIAN ENTERPRISES LTD', u'SPICEJET LTD', u'SPICEJET LTD']

我已将此列表分配给词典

record['company_present'] = set(company_list_present)

当我把它作为json返回时,我发现它会像这样返回 -

 'result': {'suspected': 95.941691412119113, 'unsuspected': 4.0583085878808909}, u'company_present': set(['DR REDDYS LABORATORIES LTD', 'ASTRA MICROWAVE PRODUCTS LTD'])

see u'company_present' value

如何将不同的列表分配给company_list_present?

1 个答案:

答案 0 :(得分:3)

您只想将您设置为列表?然后

record['company_present'] = list(set(company_list_present))