Skip to content

Tag: lambda

Factorial function using lambda

I am trying to implement the function below into one line of lambda code. def fac(num): num = int(num) if num > 1: return num * fac(num – 1) else: return 1 I have …

Using filter and lambda in a list of lists

I working with a list of lists. Each of those lists are the same — they contain title, url and some additional statistics (always in the same order). I would like to create a function find_title, which takes the wanted title and returns the whole list (with title, url and statistics). That’s my attempt However […]

python max function using ‘key’ and lambda expression

I come from OOP background and trying to learn python. I am using the max function which uses a lambda expression to return the instance of type Player having maximum totalScore among the list players. The function correctly returns instance of type Player having maximum totalScore. I am confused about the following three things: How […]

python: union keys from multiple dictionary?

I have 5 dictionaries and I want a union of their keys. I tried but it gave me an error Am I doing it wrong ? I using normal forloop but I wonder why the above code didn’t work. Answer Your solution works for the first two elements in the list, but then dict1 and dict2 got reduced into a