📜  Python - 多个列表的元组列表

📅  最后修改于: 2022-05-13 01:55:04.752000             🧑  作者: Mango

Python - 多个列表的元组列表

在本文中,我们将讨论如何将元组列表转换为多个列表。我们可以使用 map()函数将 lit 元组转换为多个列表

例子:

Input: [('a', 'b', 'c'), (1,2,3), ('1','3','4')]
Output: ['a', 'b', 'c'], [1, 2, 3], ('1', '3', '4')

示例 1:显示元组列表并显示它们的Python代码。

Python3
# list of tuple for student data
# with both integer and strings
a = [(1, 2,3,4,5),
     ("sravan","bobby","ojaswi","rohith","Gnanesh"), 
     (96,89,78,90,78)]
  
# display
print("Original list of tuple")
print(a)
  
# list of tuple for student data 
# with both integer and strings
a = [(1, 2,3,4,5),
     ("sravan","bobby","ojaswi","rohith","Gnanesh"),
     (96,89,78,90,78)]
  
# convert list of tuple to multiple lists
data = map(list, zip(*a))
  
print("")
  
# display 
print("List")
for i in data:
  print(i)


Python3
# list of tuple for student
# data with both integer and strings
a = [(1, 2,3,4,5), 
     ("sravan","bobby","ojaswi","rohith","Gnanesh"),
     (96,89,78,90,78),
     ("kakumanu","kakumanu","hyd","hyd","hyd")]
  
# convert list of tuple to multiple lists
data = map(list, zip(*a))
  
# display 
for i in data:
  print(i)


输出:



示例 2:将元组列表转换为多个列表的Python代码

蟒蛇3

# list of tuple for student
# data with both integer and strings
a = [(1, 2,3,4,5), 
     ("sravan","bobby","ojaswi","rohith","Gnanesh"),
     (96,89,78,90,78),
     ("kakumanu","kakumanu","hyd","hyd","hyd")]
  
# convert list of tuple to multiple lists
data = map(list, zip(*a))
  
# display 
for i in data:
  print(i)

输出:

[1, 'sravan', 96, 'kakumanu']
[2, 'bobby', 89, 'kakumanu']
[3, 'ojaswi', 78, 'hyd']
[4, 'rohith', 90, 'hyd']
[5, 'Gnanesh', 78, 'hyd']