Welcome to the Treehouse Community
Looking to learn something new?
Python collections - kwargs.
Hi, i am on this task for few days...
- how can i accept a list of dictionaries as an argument?
- how to use ** for each dirctory? Thanks, Oren.
Let's test unpacking dictionaries in keyword arguments. You've used the string .format() method before to fill in blank placeholders. If you give the placeholder a name, though, like in template below, you fill it in through keyword arguments to .format(), like this: template.format(name="Kenneth", food="tacos") Write a function named string_factory that accepts a list of dictionaries as an argument. Return a new list of strings made by using ** for each dictionary in the list and the template string provided.
Christopher ShawPython Web Development Techdegree Graduate 58,236 Points
The function need to accept a list. We simply give this argument a name, i.e. data
We are asked to return a list, so lets create an empty list we can add too.
We then iterate though the list we were passed, unpack the values and format the template string with the values, lastly append it to our empty list.
def string_factory(data): list =  for value in data: list.append(template.format(name=value['name'], food=value['food'])) return list
Good answer thank you. This topic is the most difficult to grasp... I still dont get it very well.. after researching online.