This community-built FAQ covers the “Capitals” exercise from the lesson “List Comprehension”.
Paths and Courses
This exercise can be found in the following Codecademy content:
FAQs on the exercise Capitals
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
This exercise asked to contain the string “capital, country” but this was not added in the solution. How are we expected to get it right if we are given faulty directions?
Yeah it had me confused at first.
“Capital, country” refers to the format that is required for the answer to be correct.
In other words, your answer has to be ordered by capital, a comma, and the country, like this:
[‘Santiago, Chile’, ‘Paris, France’, ‘Copenhagen, Denmark’]
Is there a reason these code challenges are using the python 2.7 shell? This exercise, for example, would have been a lot easier using a python 3.6+ syntax:
locations = [f'{a}, {b}' for (a,b) in zip(capitals, countries)]
capitals = ["Santiago, ", "Paris, ", "Copenhagen, "]
countries = [“Chile”, “France”, “Denmark”]
locations = zip(capitals, countries)
locations = [item1 + item2 for (item1, item2) in locations]
print(locations)
My output:
[‘Santiago, Chile’, ‘Paris, France’, ‘Copenhagen, Denmark’]
My solution is incorrect. Why?
EDIT: locations = [item1 + ", " + item2
I added the ", " directly to the first list, so it wasn’t technically correct. The ", " in between fixed my problem.