[Tutor] Convert a list to a group of separated strings

Juan Christian juan0christian at gmail.com
Thu Sep 11 19:32:45 CEST 2014


On Thu, Sep 11, 2014 at 2:07 PM, Danny Yoo <dyoo at hashcollision.org> wrote:
>
>
> Hi Juan,
>
> You have a "var-arity" function called fetch_users(), and you'd like
> to apply it with an explicit list of arguments "my_list".
>
> In this case, you want to use the application operator:
>
>
> https://docs.python.org/2/tutorial/controlflow.html#tut-unpacking-arguments
>
> ########################
> fetch_users(*my_list)
> ########################
>
> If you have other questions, please feel free to ask.
>

Indeed, this way works flawlessly, thanks.


On Thu, Sep 11, 2014 at 2:09 PM, Peter Otten <__peter__ at web.de> wrote:
>
>
> You can explode the list by invoking the function with
>
> fetch_users(*my_list) # prepend the list with a star
>
> but I recommend that you change the function's signature to
>
> def fetch_users(steamids):
>     ...
>
> and invoke it in the common way with
>
> fetch_users(my_list)
>
> That of course means that even to invoke the function with a single user
> you
> have to wrap the user's id in a list:
>
> fetch_users(["76561198048214059"])
>

I was thinking about that too, I'll try to implement that way. Which one
would be a more pythonic way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140911/de9b7962/attachment.html>


More information about the Tutor mailing list