From the course: Python for JavaScript Developers

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Map to comprehension

Solution: Map to comprehension - Python Tutorial

From the course: Python for JavaScript Developers

Start my 1-month free trial

Solution: Map to comprehension

(upbeat electronic music) - [Instructor] So the goal of this challenge was to bring the logic that filters Nobel prize laureates with an A in their first or middle name from the JavaScript portion of the application to its Python backend. And let's take a look at my solution to this. So here I am at the directory ch_05_06 at the file app.py. And the top of the application looks very similar. Then on line 13, you'll see that I define a list called firstNameWithA, and it's a list comprehension that takes each laureate for laureate in nobel_prize_laureates if A is in that laureate's first name to lower. And the reason I use that lower function is to make sure that I catch the laureates whose names have uppercase A as well as lowercase A. Then if you go down to the route section of this application you'll see that they're pretty similar, except on line 27 the items route returns the firstNamesWithA list after Jsonifying it. So…

Contents