Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Andy Hughes8,127 Points
Map comprehension. Question is confusing!
So once again, I've wasted more time than needed, overthinking the question for this challenge.
If you're doing part one, just ignore the 'dimensions' list because it's largely irrelevant for part 1. At first when I read the question and it said 'create a function named area that takes two arguments from a tuple list, I ended with this:
def area([arg1, arg2]):
(Ok so I'm still a noob!) The question doesn't mean that you're writing two arguments into the function. It simply means that the list contains a tuple with a series of paired arguments. So you need to be aware that you will reference a first item and second item.
In our area() function, our argument is going to be the variable 'dimension', which is a single argument. In essence, ignoring the 'dimensions' list altogether, this is like saying, create a function that will multiply two items together that are contained in one variable.
However, because the 'dimensions' variable contains paired items in the list, our function needs to know how to choose the first item and second items independently. So remembering [keys], we can reference our argument 'dime' and just tell it whether it's the first item '', or the second item ''.
For the second part, we're simply writing a list comprehension style query as per the end of the 'Map' video. Kenneth shows it a couple of minutes before the end.
Hope that helps someone else as it confused the heck out of me at first!
dimensions = [ (5, 5), (10, 10), (2.2, 2.3), (100, 100), (8, 70), ] def area(dime): return dime * dime areas = [area(dime) for dime in dimensions]