stack

Error return a function using if-else shorthand in python

Error return a function using if-else shorthand in python Question: I’m trying to use this if-else shorthand inside a function: def isFull(): # checks wheteher stack is full return True if top == (size – 1) else return False But my IDE highlights the return saying "Expected expression". What is wrong with the code, and …

Total answers: 1

Delimiter Pairing Using A Stack

Delimiter Pairing Using A Stack Question: I am currently taking a Data Structures & Algorithms course, and while learning about Stacks, the instructor has presented a function called check_parens(), which takes an expression as input and checks to see if the parentheses in the expression are well-balanced. The function is as follows: def check_parens(expr): s …

Total answers: 1

Program to check balanced brackets for equation

Program to check balanced brackets for equation Question: I am trying to write a program which checks balanced brackets for equation, my program is checking the brackets but its only looking for brackets and only give the right answer for the bracket but different answer for equation My expected output is exp1 = "(2+3)+(1-5)" # …

Total answers: 3

Python codility lesson : stacks and queues fish bug

Python codility lesson : stacks and queues fish bug Question: My code seems to be returning the wrong answer for one test case on codility.(rest of the test cases are correct) for a test case: large_random large random test, N = ~100,000 i’m getting a got 868 expected 840 question link: https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/ def solution(A, B): …

Total answers: 6

How to get the caller class name inside a function of another class in python?

How to get the caller class name inside a function of another class in python? Question: My objective is to stimulate a sequence diagram of an application for this I need the information about a caller and callee class names at runtime. I can successfully retrieve the caller function but not able to get a …

Total answers: 6

Does Python optimize tail recursion?

Does Python optimize tail recursion? Question: I have the following piece of code which fails with the following error: RuntimeError: maximum recursion depth exceeded I attempted to rewrite this to allow for tail recursion optimization (TCO). I believe that this code should have been successful if a TCO had taken place. def trisum(n, csum): if …

Total answers: 8

Setting stacksize in a python script

Setting stacksize in a python script Question: I am converting a csh script to a python script. The script calls a memory-intensive executable which requires a very large stack, so the csh script sets the stacksize to unlimited: limit stacksize unlimited When I try to reproduce this script in python, I execute them in a …

Total answers: 4