Can a lambda function call itself recursively in Python?

A regular function can contain a call to itself in its definition, no problem. I can't figure out how to do it with a lambda function though for the simple reason that the lambda function has no...

Django: Access primary key in models.filefield(upload_to) location

I'd like to save my files using the primary key of the entry. Here is my code: def get_nzb_filename(instance, filename): if not instance.pk: instance.save() # Does not work. ...

PHP recursive search and replace array elements

I want to recursively search and replace elements in an array. The array is tree based so looks like Object Children Object type A Object type B Object Children Object type...

Iterate over a deeply nested level of hashes in Ruby

So I have a hash, and for each level of the hash, I want to store its key and value. The problem is, a value can be another hash array. Furthermore, that hash can contain key value pairs where the...

Min and Max of a List (without using min/max function)

I was wondering if there is a way to find min & max of a list without using min/max functions in Python. So I wrote a small code for the same using recursion. My logic is very naive: I make two...

Longest Common Substring: recursive solution?

The common substring algorithm : LCS(x,y) = 1+ LCS(x[0...xi-1],y[0...yj-1] if x[xi]==y[yj] else 0 Now the Dynamic Programming solution is well understood. However I am unable to...

List all the files and folders in a Directory with PHP recursive function

I'm trying to go through all of the files in a directory, and if there is a directory, go through all of its files and so on until there are no more directories to go to. Each and every processed...

How to maintain state in Erlang?

I have seen people use dict,ordict,record for maintaining state in many blogs that i have read.I find it as very vital concept. Generally I understand the meaning of mantaining state,recursions...

A recursive function to sort a list of ints

I want to define a recursive function can sort any list of ints: def sort_l(l): if l==[]: return [] else: if len(l)==1: return [l[-1]] elif l[0]<l[1]: ...

Makefile: Generate list with subdirectories

Let's suppose I have this directory structure: -src | |-- subdir1 | | |-- subdir2 | | | |-- subdir3 I want to generate automatically a variable that finds the name of...

Check for repeated characters in a string Javascript

I was wondering if there is a way to check for repeated characters in a string without using double loop. Can this be done with recursion? An example of the code using double loop (return true or...

javascript fibonacci memoization

To calculate the nth term of the fibonacci sequence, I have the familiar recursive function: var fibonacci = function(index){ if(index<=0){ return 0; } if(index===1){ return 1; } ...

Recursively iterate through a Scala list

I'm trying to recursively iterate through a list in Scala using pattern matching. I cannot use any list functions, or while/for loops. What I need to do is iterate through the list, and remove an...

Nested dictionary sum all values

I have a seemingly easy problem, but can't solve it. Dictionary = { 'own': { 'Dun Morogh': { 'Horde': { 'chars': { 'Qiidu': { ...

Intuitive explanation of binary tree traversals without recursion

I have seen many articles and books (and Stack Overflow answers) that show how to do preorder, inorder, and postorder depth-first tree traversals iteratively, using an explicit stack instead of...

Rules governing order of macro expansion in Common Lisp

defmacro is documented at http://clhs.lisp.se/Body/m_defmac.htm but the documentation is not entirely clear on exactly when things happen. By experiment with Clisp, I have found the following...

ES6 Tail Recursion Optimisation Stack Overflow

Having read Dr Rauschmayer's description of recursive tail call optimisation in es6, I've since been trying to recreate the 'zero-stack' execution of the recursive factorial function he...

LinkedLists in python recursion

I have a simple implementation of LinkedList in python. How do I use recursion inside a method? I know how recursion works but how do I use self with recursion. It'd be nice if someone can fix my...

Pass slice as function argument, and modify the original slice

I know everything is passed by value in Go, meaning if I give a slice to a function and that function appends to the slice using the builtin append function, then the original slice will not have...

Fatal Python error: Cannot recover from stack overflow

I read on internet similar problem, but none of the answer could help me. I have a function that for each line of data (data have around 2'000'000 rows) do something and then recall the same...

Strassen Vinograd Algorithm

I got a task to write a Strassen Vinograd algorithm in C++. I have written it twice, but first version of my code don't even works. The result is correct in the lower left corner of result matrix....

Count the number of cows after N number of years

A cow has a calf every year. A calf becomes a cow in 2 years, starting with one cow we have to count how many animals are there in N years. Suppose no cow ever dies... eg at N=5: 1st cow gave 2...

Why use a helper function inside a recursive function?

In the book Functional Programming in Scala, in the context of explaining how recursion is often used in functional programming over imperative iteration, the authors show recursion via a...

Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65

I am new in react native development. I am using new MacBook Air (M1, 2020) with M1 chip. I have Installed the dependency below: Node = v14.15.3 Npm = 6.14.9 Homebrew = 2.7.0 react-native-cli:...

PhaseScriptExecution [CP-User] error in React Native

Nowadays everytime I create a new project react-native init ProjectName and after it is created I do npx pod-install and then react-native run-ios it gives me error. It happens with every project...

Is it possible to give html images more than one fallback url?

I found out that you can have a fallback URL for an <img> using onerror if the first loading fails. But it is possible to provide a list of sources (urls) to try and keep trying until one of them...

auto-py-to-exe stuck at Loading module hook 'hook-gevent.py'

I am trying to convert the code to exe with auto-py-to-exe. It stuck at "Loading module hook 'hook-gevent.py'...". import time, pyautogui, keyboard, threading from tkinter import * window =...

Replace wildcards in a binary string avoiding three identical consecutive letters

Given a string S of length N, return a string that is the result of replacing each '?' in the string S with an 'a' or a 'b' character and does not contain three identical consecutive letters (in...

Memoize multi-dimensional recursive solutions in haskell

I was solving a recursive problem in haskell, although I could get the solution I would like to cache outputs of sub problems since has over lapping sub-problem property. The question is, given a...

How does React update a component and its children after a state change?

I am watching Paul O Shannessy - Building React From Scratch And i understand the mounting process very well but i have hard day trying to understand how React update a component and its...