Now there is a need:Assuming that the user entered the English name is not standard, not according to the first letter capitalization, subsequent letter lowercase rules, please use the map () function, a list (including a number of nonstandard English names) into a list containing the canonical English name:Input: [' Adam ', ' LISA ', ' BarT ']Output: [' Adam ', ' Lisa ', ' Bart ']The original idea was to s
Map () function in python and map function in python
Map () is a high-order function built in Python. It receives a function f and a list, and uses function f in turn on each element of the list, get a new list and return it.
For example, for list [1, 2, 3, 4, 5, 6, 7, 8, 9]
If you want to square each element of the list, you can use the map () function:
Therefore, you only need to pass in the f (x) = x * x function to complete the computation using the map () function:
def f(x): return x*xp
Classes and instances1, Class: There are properties there are methods that are classes. Here is the Student class:classstudent (object): def__init__ ( Self,name,score):self.name=name self.score=scoredefprint_ Score (self): print ('%s:%s '% (self.name,self.score)) defget_grade (self): ifself.score >=90:return ' A ' elifself.score>=60: return ' B ' else:return ' C ' 2, example (instance): the specific object. Here's how the class student is created:Vincent = Student (' Vincent ', +)
will be out of the way.Take the first N elements, which are the elements indexed as 0-(N-1), and you can use loops:>>> r = [] for in range ( N): ... >>> r['Adam'Lisa ' Bart']It is cumbersome to use loops for operations that often take a specified index range, so Python provides a slice (Slice) operator that can greatly simplify this operation.Corresponding to the above problem, take the first 3 elements, a line of code to complete the slice:>>> l[0:3['Adam'Lisa' Bart']L[0:3] Indicates tha
use reduce() it to write a function that converts the string to number.Practice :Do not use the JavaScript built-in parseint () function to implement a string2int () function with the map and reduce operations:‘use strict‘;function string2int(s) { // 利用js变量弱类型转换 var s_length = s.length; if (s_length == 1) { return s * 1; } else { var arr = s.split(""); var result = arr.reduce(function (x, y) { return x * 10 + y * 1; }); return result;
# This is a learning note for the Liaoche teacher Python tutorial1 , overviewThe python built-in sorted () function can sort the list.The sorted () function is also a high-order function that can receive a key function to implement a custom sort, and the function specified by key will be applied to each element of the list and sorted according to the result returned by the key function.# Direct Sort>>> Sorted ([36, 5,-12, 9,-21])[-21,-12, 5, 9, 36]# Accept the key function sort>>> sorted ([5, -1
Pop () methodPHP (N)Delete an element from listPaul's classmates had to turn away a few days ago, so how do we remove Paul from the existing list?If Paul's classmates were in the last one, we could use the pop () method of list to delete:>>> L = [' Adam ', ' Lisa ', ' Bart ', ' Paul ']>>> L.pop ()' Paul '>>> Print L[' Adam ', ' Lisa ', ' Bart ']The Pop () method always deletes the last element of the list ,
Sliceuse only one: to indicate from beginning to end:>>> L[:][‘Adam‘, ‘Lisa‘, ‘Bart‘, ‘Paul‘]The slice operation can also specify a third parameter: The third parameter indicates that each n takes one, and the top L[::2] takes one out of every two elements, that is, one by one.Change the list to a tuple, the slice operation is exactly the same, but the result of the slice becomes a tuple.IterationThe iterative operation is for a collection, regardless
want to achieve a sort that ignores case, we just need to change the key function:>>> sorted ([' ABC ', ' abc ', ' CBA ', ' BAC '],key=str.lower) [' abc ', ' abc ', ' BAC ', ' CBA ']Further, to reverse order, you can pass in the third parameter reverse=true:>>> sorted ([' ABC ', ' abc ', ' CBA ', ' BAC '],key=str.lower,reverse=true) [' CBA ', ' BAC ', ' abc ', ' ABC ']Sorted () The key to sorting is to implement a mapping function!Practice:Use a group of tuples to represent student names and gr
Python's update setBecause set stores a set of unordered elements that are not duplicated, the update set mainly does two things:One is to add the new element to the set, and the other is to remove the existing element from the set.when adding an element, use the Add () method of Set :>>> s = Set ([1, 2, 3]) >>> S.add (4) >>> print Sset ([1, 2, 3, 4])If the added element already exists in set, add () will not error, but will not be added:>>> s = Set ([1, 2, 3]) >>> S.add (3) >>> print sset ([1,
First, the contentIi. Exercise 1, Element classificationRequirements: A collection of the following values [11,22,33,44,55,66,77,88,99,90 ...], saving all values greater than 66 to the first key in the dictionary, and saving the value less than 66 to the value of the second key.That is: {' K1 ': All values greater than 66, ' K2 ': All values less than 66}L = [11,22,33,44,55,66,77,88,99,90]d = {' K1 ': [], ' K2 ': []}for i in Range (Len (l)): if l[i] >: d[' K1 '].append ( L[i]) else:
']
});
Next, create Store,store is a collection of user, including multiple user instances.
var userstore = ext.create (' Ext.data.Store ', {
model: ' User ',///Just created user model
data: [
{name: ' Lisa ', email : ' lisa@simpsons.com ', Phone: ' 555-111-1224 '},
{name: ' Bart ', email: ' Bart@simpsons.com ', Phone: ' 555-222-1234 '},
After the model and store are created,
of user, including multiple user instances.
var userstore = ext.create (' Ext.data.Store ', {
model: ' User ',///Just created user model
data: [
{name: ' Lisa ', email : ' lisa@simpsons.com ', Phone: ' 555-111-1224 '},
{name: ' Bart ', email: ' Bart@simpsons.com ', Phone: ' 555-222-1234 '},
After the model and store are created, you can create a grid panel.
Ext.create (' Ext.gr
Using the map () function, the nonstandard English name entered by the user becomes the first letter capitalized, and the other lowercase canonical names. Input: [' Adam ', ' Lisa ', ' Bart '], output: [' Adam ', ' Lisa ', ' Bart '].The sum () function provided by Python can accept a list and sum, write a prod () function that accepts a list and uses the reduce () to calculate the product.list=[' Adam ', '
Let's look at a picture first:
"Monrolisa"
Pantene: The big wave hairstyle of the Mona Lisa
Leonardo da Vinci (not that pit Dad's furniture brand Oh pro, is one of the three Italian Renaissance Mr. Leonardo) is almost omnipotent genius, which design and painting have exceptionally high achievements, his works in addition to contain a strong humanistic color, but also full of a lot of design theory, belong to the rational faction of th
() {return this.age;} Obj1=obj;obj.age= '; Console.log (Obj1.getage ());Well, the object objects above, the built-in objects that belong to JS, except for the object type and Function,array,date,error,regexp, these built-in object types belong to reference typesvar func=new Function (' Console.log ("Hi"); var arr=new Array (' Eric ', ' Lisa ', ' Josh '), var date=new date (), Var error=new error ("Something Bad Happen"), Var reg=new REGEXP (' \\d+ ')
Recently, the nvidia exposure to a variety of GPU core and code, using 28nm technology, no 20nm GPU. Compared to NVIDIA, AMD is recognized as a process technology than Nvidia more skilled, the industry's guess is that they will launch a 20nm process earlier, but AMD official confirmed that this year will only have 28nm process products, 20nm process products are still in development.
AMD's technological progress was one of the concerns of many analysts at the AMD earnings conference yesterday.
All right. "Pride and Prejudice" is simply the originator of Korean dramas and Qiong Yao drama.
Last week after reading the novel, the weekend to see the 2005 version of the film, yesterday, again today, 1995 of the TV series and 1940 of the film to see.
Almost every episode is in mind, and Bentley moved to the Manor meet, Jane in the Bentley Manor sick to take care of Jane, arrogant Mr. Darcy bias, Darcy but unconsciously fall in love with Lisa.
G
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.