把列表换成JSON格式,并根据键取值

def get_all(content, keyword):
    keys = []
    values = []
    for specs in keyword:
        num = keyword.index(specs)
        keys.append(specs)
        if num <= len(keyword) - 2:
            values.append(keyword[num + 1])
        else:
            pass
    spec_data = dict(zip(keys, values))

    if content in spec_data:
        brand = ''.join(spec_data[f'{content}']).replace(f'{content}', '')
    else:
        brand = '暂无'
    return brand

 

posted @ 2023-11-13 09:11  布都御魂  阅读(6)  评论(0编辑  收藏  举报