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

Danny Yoo dyoo at hashcollision.org
Thu Sep 11 19:43:07 CEST 2014


> 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?


Peter's suggestion is more Pythonic.  The list argument is explicit.
It requires less esoteric knowledge of both vararity functions and the
unpacking operator.  It reads much more easily.

It wins.  :P


More information about the Tutor mailing list