1

I'd like to call something that takes 2 arguments:

def bar(arg1, arg2):
    return arg1 + arg2

But in the call I'd like to only send one thing, a list:

baz = [1, 2]
foo = bar(baz)

So that wont work, but I am familiar with a concept in Tcl that would work in this situation and it would look like this:

proc bar {arg1 arg2} {
   return arg1 + arg2
}
set baz [list 1 2]
set foo [bar {*}baz]

You'll notice the {*}. That thing, as far as I know, tells the Tcl interpreter to evaluate that and break the list apart first. so it sends in the two arguments not as one list, but as two arguments.

Does python have the same concept? I don't know what to call it, like an inline list separator or something.

user2357112
  • 260,549
  • 28
  • 431
  • 505
MetaStack
  • 3,266
  • 4
  • 30
  • 67
  • Also http://stackoverflow.com/questions/6913084/how-to-split-list-and-pass-them-as-separate-parameter, which I found with the Google keywords `python send list as separate arguments`. – user2357112 Apr 28 '17 at 20:50
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [on topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. – Prune Apr 28 '17 at 20:54
  • 2
    @Prune: It's an on-topic, well-written question; it just doesn't demonstrate good search skills. – user2357112 Apr 28 '17 at 20:56
  • @user2357112: those pages of the intro tour tell you to **research** before you post. OP didn't bother -- not even as much as searching on the question title. – Prune Apr 28 '17 at 21:03
  • @Prune: [Googling the title turns up nothing useful.](https://www.google.com/search?q=does+Python+have+a+list+spliter+like+Tcl%27s+%7B*%7D) Same with [Python inline list separator](https://www.google.com/search?q=python+inline+list+separator). Sometimes it's hard to come up with the right search keywords. – user2357112 Apr 28 '17 at 21:05
  • sorry, I just didn't know what words to use to search for the concept. But in the meantime, I've also learned you could use reduce to take care of this particular case as well. – MetaStack Apr 28 '17 at 21:06
  • I [entered the title into my search bar](https://duckduckgo.com/?q=does+Python+have+a+list+spliter+like+Tcl%27s&t=ffsb&ia=qa), and the top three items were this question and two solutions to one of the problem's two aspects. Hence the closure and down votes. – Prune Apr 28 '17 at 21:07

0 Answers0