我正在尝试将结果放入列表中。
这是我的代码:
from ise import ERS
l = ise.get_endpoints(groupID=my_group_id)['response']
这是我的输出:
[('AA:BB:CD', 'cvr5667'), ('AA:BB:CC', '8888')]
这是我想要的输出,它是括号内的第一个元素的列表:
['AA:BB:CD','AA:BB:CC']
我是python的新手,正在使用列表/字典,因此任何建议都可以。我正在尝试做的就是将括号中的第一个元素放在一个列表中,如我所示。
答案 0 :(得分:2)
使用列表理解(如注释中所建议):
lst_1 = [('AA:BB:CD', 'cvr5667'), ('AA:BB:CC', '8888')]
lst_result = [i[0] for i in lst_1]
答案 1 :(得分:-1)
有这样的东西吗?
result = [('AA:BB:CD', 'cvr5667'), ('AA:BB:CC', '8888')]
first_elements_to_list = [tmp[0] for tmp in result]
print(first_elements_to_list)
打印:
['AA:BB:CD', 'AA:BB:CC']