Answers for "how to group lists per index in python"

0

how to group lists per index in python

# initializing the list
lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# empty list
result = []
# variable to 0
index = 0
# iterating over the sub_list length (3) times
for i in range(len(lists[0])):
   # appending an empty sub_list
   result.append([])
   # iterating lists length (3) times
   for j in range(len(lists)):
      # adding the element to the result
      result[index].append(lists[j][index])
# moving to the next index
index += 1
# printing the result
print(result)
Posted by: Guest on June-04-2021

Code answers related to "how to group lists per index in python"

Python Answers by Framework

Browse Popular Code Answers by Language