使用Python3将列表转换为字典

时间:2017-03-02 15:58:58

标签: python json python-3.x

我是新手:)

我需要将这个简单的列表转换为字典:

F[i] + L[j_i] >= K

输出将为[('Host', '127.0.0.1:8000'), ('Connection', 'keep-alive'), ('Cache-Control', 'no-cache'), ('Test_data_Header_Key', 'Test_Data_Header_value'), ('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'), ('Postman-Token', '3b17e573-90d6-e5fe-26cb-a9488f9b22e0'), ('Accept', '*/*'), ('Accept-Encoding', 'gzip, deflate, sdch, br'), ('Accept-Language', 'en-US,en;q=0.8,bn;q=0.6')]

感谢您的建议。感谢。

1 个答案:

答案 0 :(得分:3)

dict构造函数已经为您执行此操作:

dict([('Host', '127.0.0.1:8000'), ('Connection', 'keep-alive'), ('Cache-Control', 'no-cache'), ('Test_data_Header_Key', 'Test_Data_Header_value'), ('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'), ('Postman-Token', '3b17e573-90d6-e5fe-26cb-a9488f9b22e0'), ('Accept', '*/*'), ('Accept-Encoding', 'gzip, deflate, sdch, br'), ('Accept-Language', 'en-US,en;q=0.8,bn;q=0.6')])