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

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


On Thu, Sep 11, 2014 at 9:42 AM, Juan Christian
<juan0christian at gmail.com> wrote:
> Let's say I have the following list: my_list = ['76561198048214059',
> '76561198065852182', '76561198067017670', '76561198077080978',
> '76561198077257977', '7656119807971
> 7745', '76561198088368223', '76561198144945778']
>
> and I have a function with the following signature: def
> fetch_users(*steamids)
>
> Usage: fetch_users("76561198048214059", "76561198065852182",
> "76561198067017670", [...])

[text cut]

> The problem is that when I give the 'my_list' directly to 'fetch_users'
> function it gives me "TypeError: sequence item 0: expected str instance,
> list found".

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.


More information about the Tutor mailing list