Q:

Write a Python program to extract a specified column from a given nested list

0

Write a Python program to extract a specified column from a given nested list. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def remove_column(nums, n):
   result = [i.pop(n) for i in nums]
   return result 

list1 = [[1, 2, 3], [2, 4, 5], [1, 1, 1]]
n = 0
print("Original Nested list:")
print(list1)
print("Extract 1st column:")
print(remove_column(list1, n))

list2 = [[1, 2, 3], [-2, 4, -5], [1, -1, 1]]
n = 2
print("\nOriginal Nested list:")
print(list2)
print("Extract 3rd column:")
print(remove_column(list2, n))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now