- [Instructor] So let's try writing our own…comprehension to work on a list of values.…Here in visual studio code,…I'll open up listcomp_start.py,…in my comprehensions folder.…And you can see,…I have already defined two lists of numbers.…One of the even numbers and one of the odd.…So, first let's try doing things the old way.…Let's use the map and filter functions,…to create a list of numbers that are squares…of the original numbers in the list.…
So first I'm going to use my map…and list functions.…So I'll name the result evenSquared…and I'll put this in the list…and then I'll have a map.…And the map function is going to use a lambda.…Which we learned about earlier.…So i'll use lambda e…and that will just simply square the number.…And I'll apply that to the evens list.…And then ill just simply print…even squared.…Okay, so let's go ahead and run that.…
And you can see, there in the output that…I have a list of numbers that…are squares of the original numbers.…Okay, so now let's try adding a filter.…Suppose we wanted to apply the square function…
- Truth value testing
- Template strings
- Advanced Python functions
- Advanced collections
- Advanced classes and objects
- Python comprehensions: list, dictionary, and set
Skill Level Advanced
1. Python Language Features
2. Built-In Functions
3. Advanced Python Functions
4. Advanced Collections
5. Advanced Classes and Objects
6. Using Logging
7. Python Comprehensions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.