17

I've seen lambda functions, with an argument of *x. Is it a way you put in a list or a tuple, if it is a tuple how would you put a list as an argument parameter and vice versa.

If you could link me to some documentation, I would be grateful.

The lambda function in question:

import os
add_to_place = lambda *x : os.path.abspath(os.path.join(os.path.dirname(__file__), *x))

Thanks in advance. I've deduced that it is a tuple, but I'd like some documentation, just to be sure.

newacct
  • 119,665
  • 29
  • 163
  • 224
Games Brainiac
  • 80,178
  • 33
  • 141
  • 199
  • How does it take list as an input if in this case a tuple is required? – Games Brainiac May 28 '13 at 07:59
  • 4
    @GamesBrainiac It takes **any** iterable and converts it to a tuple of arguments – jamylak May 28 '13 at 08:00
  • @jamylak : Thanks, that makes a lot of sense. – Games Brainiac May 28 '13 at 08:02
  • 12
    @jamylak: Why is this question marked as a dupe? None of the linked questions mention lambda functions, and I landed on this page when I did a websearch for 'python lambda asterisk'. I have some understanding about lambda functions and the asterisk operator individually, but felt I needed help understanding how they work combined. I do think this question needs a better title, but if it's an 'exact duplicate' of another question, it's not obvious to me which question it duplicates. – Michael Scheper May 24 '16 at 19:59
  • @MichaelScheper It's marked as a dupe because the asterisk is used exactly the same. – jamylak May 25 '16 at 02:29
  • @jamylak: But this question is at least as much about lambda functions as the asterisk operator. And as I said (hopefully you read my whole comment), none of allegedly duplicate questions mention lambda functions at all. Surely, in cases like this, tests for equivalence should be conjunctive, not disjunctive? – Michael Scheper May 31 '16 at 05:16
  • 1
    @MichaelScheper It just doesn't seem to be large enough of a distinction to need its own question, since a `lambda` is just an anonymous function and works with the asterisk operator in the exact same way `def` does. Using a `lambda` doesn't change the question enough in my opinion, and I guess it is just an opinion but at least 4 other users also voted to close as duplicate – jamylak May 31 '16 at 08:47
  • 3
    @jamylak: I accept that. This question did save me doing further searching, though, so if future readers upvote my comments, maybe you'll reconsider. Otherwise, I'll just accept that my mind, for whatever reason, doesn't combine the two concepts quite as easily as most Python minds. ☺ – Michael Scheper Jun 12 '16 at 09:18

0 Answers0