Write a function in Python PUSH_IN(L), where L is a list of numbers. From
this list, push all even numbers into a stack which is implemented by using
another list.
Answers
Answered by
7
PUSH_IN = lambda L: [n for n in L if n % 2 == 0]
L = [n for n in range(1, 11)]
print(PUSH_IN(L))
Answered by
1
The code for pushing all the even numbers into a stack from a list of numbers ( L ) which is implemented using another list is shown below:
def PUSH( Arr, value ):
s=[]
for x in range( 0, len(Arr) ):
if Arr[x]%2==0:
s.append (Arr[x])
if len(s)==0:
print("Empty Stack")
else:
print(s)
In this, a code can be written shortly to group all the even numbers in a set of numbers given.
#SPJ2
Similar questions