Skip to content

Tag: recursion

Finding index in nested list

I am trying to create a function that will take as input a nested list and an item, and return a list of indices. For example list = [0, 5, [6, 8, [7, 3, 6]], 9, 10] and item = 7 should return [2, 2, 0], since list[2][2][0] = 7 my code should work since I can print the desires

Confusion in recursion program of python

Hey guys can anyone explain that output to me? Don’t get why its counting down again. OUTPUT: Answer To understand this you need to understand how recursion works. It works on the concept of stacks. You can have a look at the following link, to get a clear understanding : https://www.freecodecamp.org/ne…

knight tour iteration dead end

I am trying to implement knight tour using iteration method. I have already wrote a program using recursion and its working fine, now instead of recursion I am using iteration method with stack to implement knight tour, I have wrote the below code. and here I can not backtrack when I reached to a dead end, co…

Python Recursive Knight Tour

I’m trying to solve the knight tour algorithms with recursive backtracking method in python. The solution should be a matrix with 24 documented steps, but it only count up-to 5 steps. It doesn’t enter the recursive if statement. Answer The problem I see is that you set yNeu = x + pos[1] when you p…

A recursive function to sort a list of ints

I want to define a recursive function can sort any list of ints: Calling this function on a list [3, 1, 2,4,7,5,6,9,8] should give me: But I get: Please help me to fix the problem, actual code would be appreciated. Thanks! Answer The quick sort is recursive and easy to implement in Python: will give:

Python quicksort – one list – swaps

**I need to make a quicksort algorithm but so that it uses only one list and does swaps inside of it. I managed to make it “sort” or position the first element but now i don’t know how to implement the recursion. The biggest problem I’m having is how to recursively work on a part of th…