Skip to content
Advertisement

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

How can I write “EvenWord” Recursive in Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question We tried to solve the following problem with friends but we couldn’t come to a conclusion. How can we approach

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/news/how-recursion-works-explained-with-flowcharts-and-a-video-de61f40cb7f9/ You are calling the same function again if i<3,

Code that is able to search for a string in a text recursively

I have a code which satisfies the question above. However, I am personally curious on how to recode it such that if the text did not have a space and is given as “LoveIsWar”, the code will still return true if the string is “War”. However, I thought of doing a check for letter by letter but I am unsure

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, could you please check

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 probably meant yNeu = y +

getattr and setattr on nested subobjects / chained properties?

I have an object (Person) that has multiple subobjects (Pet, Residence) as properties. I want to be able to dynamically set the properties of these subobjects like so: Currently I get the wrong output: {‘pet’: <__main__.Pet object at 0x10c5ec050>, ‘residence’: <__main__.Residence object at 0x10c5ec0d0>, ‘pet.name’: ‘Sparky’, ‘residence.type’: ‘Apartment’} As you can see, instead of setting the name attribute on the

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 the list instead of

Advertisement