This community-built FAQ covers the “Ages” exercise from the lesson “List Comprehension”.
Paths and Courses
This exercise can be found in the following Codecademy content: Visualize data with Python
FAQs on the exercise Ages
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!
I’m just wondering if this is the simplest / fastest approach to this question. I know it returns the correct result, but I’m not sure if it’s the acceptable/common way to get it.
I’m getting a syntax error for this, looking for help on the issue.
Is this because f-strings are being evaluated first that is the issue, or did i make a mistake somewhere?
names = ["Jon", "Arya", "Ned"]
ages = [14, 9, 35]
users = [f"Name: {a}, Age: {b}" for (a, b) in zip(names,ages]
Just a heads-up: we can’t use f-strings for this exercise (or any of these code challenges, it seems) since the default shell is somehow set to python 2.7. This explains why the users above keep running into syntax errors.
As of writing (december 1st, 2020) the following:
Oh thank you. I totally missed that little nugget of information. I have not touched python 2 in ages and have effectively banished it from my mind, but I think it’d behove me to look back at it once in a while.
F-strings don’t work with list comprehensions in codeacademy env, yet they work in my terminal (python 3) just fine. I’ve been told that f-strings are the standard in current python3 programing, and indeed I see them everywhere on stack overflow so… did I mess up somewhere or should I report this as a bug?
After you have cast an integer to a string, you can concatenate it to another string by using + :
“I have " + str(100) + " cats!”
“I have 100 cats!”
row_count = 20
"This spreadsheet has a row count of: " + row_count
“This spreadsheet has a row count of: 20”
My issue is - did they pass row_count to a string? I don’t see that. What is this meant to be an example of? When I ran their code, it didn’t work, because row_count was not a string. Am I being an idiot about something, or did they just make a content gaff?