今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
List comprehensions
- [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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。