Welcome to the Treehouse Community
Looking to learn something new?
Gryphon Chandler12,668 Points
How do I call a function on a flattened version of a list?
I have a function that takes in an integer. Then, it creates a list that is that long. It then needs to call a function on the entire list at the same time, as shown below:
def my_function(length): temp_list = make_list(length) return mystery(temp_list, temp_list, temp_list, temp_list ...)
Essentially, the code needs to do this, but for every single item in temp_list. Also, I can't change make_list() or mystery().
Steven Parker216,083 Points
You just need the unpack operator ("
Also called the "splat" operator, it unpacks your list into individual arguments:
def my_function(length): temp_list = make_list(length) return mystery(*temp_list)