+ 3
Please how do we make lambda take 2 or more arguments?
Lambda
36 Answers
+ 13
By separating them by commas.
lambda x, y, z: None
Takes 3 arguments.
+ 7
(lambda x, y, z: x * y + z)(6, 4, 11) #35
+ 5
Yusuf Shuaib Olalekan Your task is not clear.
You wrote:
----
"What I want to achieve is to filter a list of numbers and find any three number in that list whose sum is not more than another know (sic) number"
----
Are you saying the sum of all 3 numbers or any 2 out of the 3 numbers cannot exceed any known numbers?
Are known numbers those numbers not included in the filtered list?
Assuming known numbers don't include any of the 3 in the list and the sum is based on all 3 filtered numbers, then wouldn't the answer be the 3 lowest values only if their sum is lower than the 4th lowest value? Otherwise, the result would be None?
The details matter. Otherwise, it's unclear what you are attempting to accomplish.
+ 5
Yusuf Shuaib Olalekan Actually I think I have a solution now, you need to sort the list, from min to max.
Then:
compare sum(l[i:i + 3]) to l[i + 3]
if condition:
slice l[i:i + 3] off
else:
i += 1
repeat until i + 3 == len(l) or len(l) < 4
+ 5
Yusuf Shuaib Olalekan Ah... yes... that makes complete sense. šš
So in the case of using the list [1,3,5,6,8] for the number 19, multiple valid answers could be any combination except:
[5,6,8]
But for the number 9, the only valid combination would be:
[1,3,5]
And for 12, all possible combinations are:
[1,3,5]
[1,3,6]
[1,3,8]
Thanks for that clarification. The examples are always great for making these much clearer.
+ 5
Jack, jump into the tutorial of the language you want to learn, and start learning.
Don't forget to practice with your own hands everything you read about.
And please, don't ask your questions in the question of another person.
First use the search function, and if that doesn't give you an answer, post a new question of your own.
+ 4
Yusuf Shuaib Olalekan
I think that the best tool is nested for loop.
+ 3
Yusuf Shuaib Olalekan You can use any statements that have ability to evaluate to something.
You can use comparison with any amount of arguments, but you can't use if statement, but you can use ternary operator.
+ 3
Do you want to get all sublist that meet the condition, or just one and you don't care which?
+ 2
Seb TheS Alright, I will give a trial and tell you the outcome.
+ 1
+ 1
Yusuf Shuaib Olalekan I don't think filter would be the right tool for that.
+ 1
TypeError?
+ 1
Show
+ 1
Yusuf Shuaib Olalekan How TypeError was described?
+ 1
3d loops are required, because function takes 3 arguments.
+ 1
David Carroll I have a list containing numbers (say [1,3,5,6,8]), and another number (say, 12). Then I want to get a list containing any three number from my first list, such that the sum of the content of the new list will not <= the other number(12).
Do you understand?
+ 1
Yusuf Shuaib Olalekan I got the idea work, but I've no idea what you did to get None.
+ 1
E. G:
a = lambda *s:sum(s)
print(a(1,2,3,4,5))
This will print out 15