← Back to challenges

Format IX: Unpacking Lists

PythonHardformattingstringslanguage_fundamentals

Instructions

For each challenge of this series you do not need to submit a function. Instead, you need to submit a template string that can be formatted in order to get a certain outcome.

Write three lists and a template string according to the following example. Notice the keyword argument elem:

Example

lst1 = [yourlisthere]
lst2 = [yourlisthere]
lst3 = [yourlisthere]
template = "yourtemplatestringhere"

template.format(*lst1, elem="friends") ➞ "My friends are: John, Joe and Jack."
template.format(*lst2, elem="loves") ➞ "My loves are: E, da and bit."
template.format(*lst3, elem="pokemon") ➞ "My pokemon are: Metapod, Magikarp and Unown."

Tips

The elements of a list can be unpacked and passed to .format() as positional arguments using the star operator *:

names = ["Mary", "May"]
"{} and {}.".format(*names) ➞ "Mary and May."

Notes

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Burglary Series (06): Convert to Number