Computer Science, asked by praveenyadav032003, 4 months ago

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 jai696
7

\large\mathsf\color{pink}{Solution\: using\: python\: 3}

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))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by SteffiPaul
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