A. Write the function remove_negative(Lst) to remove the negative elements and return the
positive elements from a list.
Example:
Lst = [-1, 0,2,-4,12]
#Should return list with positive elements
Lst = [ 0,2,12]
B. Write a program to duplicate all the elements of a list.
Example:
Lst=[1,2,3]
#Should return
Lst=[1,1,2,2,3,3]
C. Write a program to check if an element of a list is a prime number. If it is prime, return True
or else return False.
Example:
List1=[3,17,9,2,4,8]
#Should display
Lsit1=[True, True, False, False, False, False]
D. Write the function remove_fi rst_last(list) to remove the fi rst and last element from a list.
Example:
List1=[10,20,30,40,50]
removeFirstAndLast(Lis1)
#should return
[20, 30, 40]
E. Write a function Extract_Even(List) to return all even numbers from a list.
Example:
List1=[1,2,3,4,5,6]
Extract_Even(List1)
#should return [2,4,6]
Leave a Reply