Quote:
Originally Posted by tyler_cracker
not entirely sure what you mean, but there are a few ways "un-ordered arguments" can be useful:
- being able to just throw a dictionary of name-value pairs at a function instead of remembering "ok it wants foo, bar, baz... or is it foo, baz, bar?"
- being able to leave out args you don't care about/don't know about. handy for lots of things, though i'll admit i don't have a great use case for doing this with a lambda -- probably because i don't do a lot of functional programming in python.
And here I thought functools suggested functional programming tools.
<-- Tail call recursion fail, obv?
This is all good answers, but I guess I'm too amateur to see how it is helpful outside of command-line usage, whether you are talking about a named or anon function. Just seems sloppy to think you would need a function that takes so many arguments you can't conceivably run a program without making something out-of-order. Inside a program, I wouldn't want to do this trick, since I can already see it turning into a massive bug unless there is a comment that says: "hey, these are out of order, go look at file xyz to see what the issue is..." or maybe you have the offending function copy/pasted in the comment area, but that's just my initial impression.
When I read "out of order arguments," it sounds like there is an issue with a function trying to take way too many arguments to work on many different things and perhaps the function arguments aren't semantic, which I would think is going to be necessary if you have a function with so many arguments it can become confusing. I'm not saying there should be maximum amount of arguments as a rule per se, and there are times I would be able to appreciate this feature during debugging.
I'll admit that there a few issues with my logic.
don't get me wrong, I do use stuff like:
def myFun(one=1, two=2, three=3): pass
myFun(one=4)
Well, not THAT, of course...
Quote:
Originally Posted by Xhad
What does lambda have to do with unordered arguments?
Code:
def foo(a, b):
return (a,b)
>> foo(b=3, a=4)
(4, 3)
>> foo(**{'b': 4, 'a': 3})
(3, 4)
Sorry, I wasn't clear. According to this, functools.partial does not accept out-of-order arguments, whereas lambda does, but that should be true when you consider lambda an anonymous function:
http://stackoverflow.com/questions/5...tion-vs-lambda
Some more links I found on front page of [everyone's favorite search engine]:
http://stackoverflow.com/questions/3...tial-necessary
funny how this one seques into itertools and then how to use lambda and functools:
http://stackoverflow.com/questions/2...ilter-function
Anyways, all of this makes me exited to look into functools.