Practice 12 - Python Array
Practice 12 - Python Array
n = len(list1)
for i in range(n) :
if list1[i] == target:
return i
return -1
list1 = list1.split()
if index < 0:
else:
list1 = n.split()
for i in range(0,len(list1)):
list1[i] = int(list1[i])
list2 = []
for i in list1:
if (i%5 != 0):
list2.append(i)
else:
continue
if(list2 == []):
else:
for i in list2:
print(i,end=" ")
Given a list 'A' of N numbers (integers), you have to write a program which prints the sum of the elements of
list 'A' with the corresponding elements of the reverse of the list 'A'.
l1 = x.split()
for i in range(len(l1)):
l1[i] = int(l1[i])
l2 = l1[::-1]
for i in range(len(l2)):
l2[i] = int(l2[i])
i=0
l3 = []
while(i<len(l1)):
l3.append(l1[i]+l2[i])
i+=1
print("Resultant list:",l3)
By using list comprehension, write a program to print the input list after removing an integer 'n' from it.
#Initializing/Creating a list
for i in range(len(li)):
li[i] = int(li[i])
print(lst)
Write a program to print the list after removing all even numbers
print('List is:',result)
list1 = data.split(",")
if list1[0] == list1[-1]:
print("equal")
else:
print("not equal")
Create two lists with the user-given elements. Write a program to check whether the first or last elements of two
lists are the same or not. If yes print True, otherwise print False as shown in the examples.
list1 = data1.split(",")
list2 = data2.split(",")
print("True")
else:
print("False")
By using list comprehension, write a program to print the square of each odd number in the user list.
Constraints:
for i in range(len(lst)):
lst[i] = int(lst[i])
if(lst_1 == []):
else:
print(*lst_1,sep = ",")
Write a Python program that defines a matrix and prints matrices.
A matrix is a rectangular table of elements. The following is a 2x4 matrix, meaning there are 2 rows, 4 columns:
Matrix Representation:
5 4 7 11
3 3 8 17
In Python and other programming languages, a matrix is often represented with a list of lists. The sample matrix
above could be created with:
matrix = []
for i in range(0,m):
matrix += [0]
matrix[i] = [0]*n
# Get input
matrix[i][j] = int(input())
print (matrix)
Create an integer List with user-given input. Write a program to print True if the first or last element of the List
is 3, otherwise print False
list1 = data.split(",")
list1[i] = int(list1[i])
print("True")
else:
print("False")