python列表
怎么能够将下面列表中每个列表中的第一个元素取出来放在一起[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
就比如['1','4','7'],['2','5','8']这样存放
求大佬指点 本帖最后由 isdkz 于 2022-3-14 09:51 编辑
>>> arr = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
>>> list(zip(*arr))
[('1', '4', '7'), ('2', '5', '8'), ('3', '6', '9')]
>>> list(map(list,zip(*arr)))
[['1', '4', '7'], ['2', '5', '8'], ['3', '6', '9']]
>>>
arr = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
arr1 = list(zip(*arr))
arr2 = list(map(list,zip(*arr)))
print(arr1)
print(arr2) arr = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
arr =
print(arr)[['1', '4', '7'], ['2', '5', '8'], ['3', '6', '9']]
页:
[1]