我有一个由字符串和另一个列表组成的元组列表;
[['string1a1', 'string1b1'],
['string2a2', 'string2b2'],
['string3a3', 'string3b3']]
我无法弄清楚使用列表理解来得出类似的结果;
results = [join(ministring, i) for i in (miniarray for (ministring, miniarray) in myarray)]
我尝试过类似的
Problem 1
- Installation request for symfony/symfony v3.3.17 -> satisfiable by symfony/symfony[v3.3.17].
- don't install symfony/var-dumper v4.0.12|don't install symfony/symfony v3.3.17
- Installation request for symfony/var-dumper v4.0.12 -> satisfiable by symfony/var-dumper[v4.0.12].
但是我对扩展/表达式(?)中的每个变量范围感到困惑。
答案 0 :(得分:3)
就这么简单:
{
"103.46.233.22:83":
{
"allowed":["get","post","cookie","referer","user_agent"],
"disallowed":[],
"proxy_level":"transparent",
"info":
{
"url":"http:\/\/test.com\/ping.php?q=query",
"content_type":"text\/html; charset=UTF-8",
"http_code":200,
"header_size":385,
"request_size":318,
"filetime":-1,
"ssl_verify_result":0,
"redirect_count":0,
"total_time":1.547,
"namelookup_time":1.0e-6,
"connect_time":0.328,
"pretransfer_time":0.328,
"size_upload":143,
"size_download":127,
"speed_download":82,
"speed_upload":92,
"download_content_length":-1,
"upload_content_length":143,
"starttransfer_time":0.328,
"redirect_time":0,
"redirect_url":"",
"primary_ip":"103.46.233.22",
"certinfo":[],
"primary_port":83,
"local_ip":"172.20.0.250",
"local_port":52594
}
},
"106.233.22.13:8080":
{
"allowed":["get","post","cookie","referer","user_agent"],
"disallowed":[],
"proxy_level":"transparent",
"info":
{
"url":"http:\/\/test.com\/ping.php?q=query",
"content_type":"text\/html; charset=UTF-8",
"http_code":200,
"header_size":385,
"request_size":318,
"filetime":-1,
"ssl_verify_result":0,
"redirect_count":0,
"total_time":1.547,
"namelookup_time":1.0e-6,
"connect_time":0.328,
"pretransfer_time":0.328,
"size_upload":143,
"size_download":127,
"speed_download":82,
"speed_upload":92,
"download_content_length":-1,
"upload_content_length":143,
"starttransfer_time":0.328,
"redirect_time":0,
"redirect_url":"",
"primary_ip":"106.233.22.13",
"certinfo":[],
"primary_port":8080,
"local_ip":"172.20.0.250",
"local_port":52594
}
}
}
返回:
lst = [('string1', ['a1', 'b1']),
('string2', ['a2', 'b2']),
('string3', ['a3', 'b3'])]
res = [[master + tail for tail in sublist] for master, sublist in lst]
请注意,采用这种方法时,元组内部子列表的长度是固定的。它可以任意长。
答案 1 :(得分:3)
您可以执行以下操作:
data = [('string1', ['a1', 'b1']),
('string2', ['a2', 'b2']),
('string3', ['a3', 'b3'])]
result = [[s + e1, s + e2] for s, [e1, e2] in data]
print(result)
输出
[['string1a1', 'string1b1'], ['string2a2', 'string2b2'], ['string3a3', 'string3b3']]
请注意,这假设内部列表仅包含两个元素。
答案 2 :(得分:0)
尝试一下:
new_list = list(map(lambda x: [x[0]+x[1][0], x[0]+x[1][1]],data))