Question: Exercise 1 Remove Duplicates Using Pop. A . Create a list from the numbers entered. The first number represents the length of the list and

Exercise 1 Remove Duplicates Using Pop.
A. Create a list from the numbers entered. The first number represents the length of
the list and others are the elements of the list. Print the list.
Sample input:
8
1
2
2
3
1
4
4
5
Sample output:
[1,2,2,3,1,4,4,5]
B. Define a function create
_unique_list(lst), which gets the list entered in A. In the
function, iteratively pop elements until all remaining elements are unique. Return
both the modified list in ascending order and the list of removed duplicates. Print
both lists after calling the function.
Sample output:
[1,2,3,4,5]
[4,2,1]2
Exercise 2 Transpose.
A. Create a 2x3 matrix by entering strings. Print the matrix.
Sample input:
abc
def
ghi
jkl
mno
pqr
Sample output:
["abc", "def", "ghi"]
["jkl", "mno", "pqr"]
B. Transpose the matrix of strings in A and reverse each string in the transposed
matrix.
Sample Output:
[['cba','lkj'],['fed', 'onm'],['ihg','rqp']]
Exercise 3 Cartesian Product Filtering by Sum.
A. Given two lists, create a list of pairs of the Cartesian product [a, b] but only include
pairs where the sum is divisible by 3 by using for loops.
Sample Input:
list1=[1,2,3]
list2=[4,5,6]
Sample Output:
[[1,5],[2,4],[3,6]]
B. Given two lists, create a list of pairs of the Cartesian product [a, b] but only include
pairs where the sum is divisible by 3 using list comprehension.
Sample Input:
list1=[1,2,3]
list2=[4,5,6]
Sample Output:
[[1,5],[2,4],[3,6]]3
Exercise 4 Matrix Flattening with Conditions.
Given a 2D matrix, create a flattened and sorted list consisting of squares of only even
numbers in the matrix by using list comprehension. Print the flattened and sorted the
list of squares of even numbers.
Sample Input:
matrix =[[7,5,3],[8,5,6],[2,1,9]]
Sample Output:
[4,16,36,64]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!