;> s[::-1]'CBA'6, remove the numbers in the string, and then sort, if the same letters appear, such as AA, uppercase letters in front of lowercase letters#!/usr/bin/python#Coding:utf-8s='ABCDBA233ABC1'L=Sorted (s) upper_list=[]lower_list= [] forVinchL:ifv.isupper (): Upper_list.append (v)elifv.islower (): Lower_list.append (v)Else: Pass#print upper_list, lower_list forXinchUpper_list:x_lower=X.lower ()ifX_lowerinchLower_list:lower_list.insert (
fromBstImportBeautifulSoup#get the contents of the page to crawl by gettingret = Requests.get (url='https://www.autohome.com.cn/news/')#sets the encoding for the acquired content (Apparent_encoding gets the encoding of the current content)Ret.encoding =ret.apparent_encoding#parse the acquired content with the BeautifulSoup moduleSoup = ret. BeautifulSoup (Ret.text,'Html.parser')#Html.parser is the way of parsing #Find finds the first object Find_all finds all objects returns a list of objects
Using the functions in Sklearn makes it easy to divide the data into trainset and TestsetThe function is Sklearn.cross_validation.train_test_split and uses the following:Import NumPy as NP from Import train_test_split>>> X, y = Np.arange (Ten). Reshape ((5, 2)), Range (5)>>>1 ],[2, 3],[4, 5],[6, 7],[8, 9]])>>>1, 2, 3, 4]>>> X_train, X_test, y_train, y_test = train_test_split (... X, y, test_size=0.33, random_state=42) ... >>> X_trainarray ([[4, 51],[6, 7]])>>> y_train[2, 0, 3 ]>>> x_testarray (
'].append (i) Print dic#用默认字典方式Import collections#coding:utf-8li=[11, 33,44,55,66,77,88,99,90] #用默认字典方法提前定义value的数据类型dic = Collections.defaultdict (list) for value in Li:if value>66:dic[' K1 '].append (value) else:dic[' K2 ']. Append (value) print dicQueue#队列分为双向队列和单向队列, all queues are process-safe.Two-way queue is the queue on both sides can be increased or decreased operation, is FIFO modeOne-way queues can increment and decrement operations only one side, so a one-way queue is a stack.This a
can do to set the% (Levelno) S: Print the value of the log level% (levelname) S: Print log level name% (pathname) s: Prints the path of the currently executing program, which is actually sys.argv[0]% (filename) s: Prints the current name of the executing program% (funcName) s: Print the current function of the log% (Lineno) d: Print the current line number of the log% (asctime) s: Time to print logs% (thread) d: Print thread ID% (threadname) s: Print thread name% (process) d: Print process ID%
formatImport re#1l=[' 2016-05-23 ', ' 2016-06-11 ', ' 2016-07-12 ']l1= ' 2016-05-23 ' Print (Re.sub (' (\d{4})-(\d{2})-(\d{2}) ', R ' \2 /\3/\1 ', L1))ResultsThe second method ofImport re#1l=[' 2016-05-23 ', ' 2016-06-11 ', ' 2016-07-12 ']l1= ' 2016-05-23 ' Print (Re.sub (? P10. String concatenationThe first of these methodsBut this method wastes memory, here is the second method, with the join11, adjust the center of the string, align left and rights= ' abc ' Print (s.ljust) print (S.ljust (+,
The judgment of 1.square numberFrom math import sqrtdef is_quare (n): PointFrom math import sqrtThe Is_integer () command uses the% use of residual symbolsReturn () can be returned directly to T or F2. Fighters and one winnersPointCeil () takes the integer command, "taking into account the fact that the damage value is more than integer, so use Ceil () rounding"Attrgetter () position command?? "Attribute can create it yourself, such as the turn attribute in this example"3. Find needle in the
First, review:1, the process: The core is the process, the process is the steps to solve the problem, that is, what to do first, what to do, based on process-oriented design procedures, like in the design of a pipeline, is a mechanical thinking method.Pros: Complex questions to simplifyCons: Poor scalability (holding a body)Application scenario: Linux kernel, httpd,git2, Object-oriented programming: The core is the object, to understand the object should regard themselves as God, in the eyes of
This script is a training Keras mnist digital Recognition program, previously sent, today to achieve the forecast,
# larger CNN for the mnist Dataset # 2.Negative dimension size caused by subtracting 5 from 1 for ' conv2d_4/convolution ' ( OP: ' conv2d ') with input shapes # 3.userwarning:update your ' conv2d ' call to the Keras 2 Api:http://blog.csdn.net/johini eli/article/details/69222956 # 4.Error checking input:expected conv2d_1_input to have sha
#-*-Coding:utf-8-*-"" "Created on Tue June 15:24:19 2015@author:hd" "" from sklearn import cross_validationc = []j=0fi Lename = R ' C:\Users\hd\Desktop\bookmarks\bookmarks.arff ' Out_train = open (R ' C:\Users\hd\Desktop\bookmarks\ Train.arff ', ' w ') out_test = open (R ' C:\Users\hd\Desktop\bookmarks\test.arff ', ' W ') for line in open (filename): # Items = Line.strip (). Split () C.append (line) c_train,c_test = cross_validation.train_test_split (c,test_size = 0.6) For i in C_train:
(' \ n '). Strip ("")] Biaotouen = [' Co Lor ', ' root ', ' sound ', ' strip ', ' texture ', ' feel ', ' label '] biaotoudict = {} for index in range (len (Biaotouen)): Biaotoudict[biaotouc[index]] = Biaotouen[index] res = [] for eachline in Fileread.readlines (): Eachlinearray = Eachline.split (', ') Reselem = [] for Elemindex in range (len (eachlinearray)): Eachlinearrayelemindexop=eachlinearray[eleminde X].strip (' \ n '). Strip ("") if (Biaotoudict.has_key (Biaotou[elemindex])
Python's dictionary is a very convenient data structure, using which we can easily find his grades, rankings, etc. by name (key) without having to traverse the entire dataset.For example: {' Lee ': [1, +], ' Jane ': [2, 98] ...}But in the process of using the dictionary, there are some problems, that is, the dictionary itself is regardless of the order you enter>>> d = {}>>> d['Lee'] = [1, 100]>>> d['Jane'] = [2, 98]>>> d['Tom']=[3,96]>>>d{'Jane': [2, 98],'Lee': [1, 100],'Tom': [3, 96]}When this
Python Intensive Training Note (7)-use the deque queue and save the object as a file,
The deque object in the collections module is a queue with the first-in-first-out principle for normal queues. We can use this object to save data.
For example, the system starts to randomly roll a game with a guess number ~ Then, the keyboard starts to receive your input. The number system will tell you whether the input
#运行的结果被修改了If you want to prevent this from happening, you can set the field to privateClass WGW (object): Def __init__ (self,name,age): Self.__name=name #在字段名前面加两个下划线表示将该字段设置为私有 self.age=ageWhen set to private, the field is only called inside the class and cannot be accessed externally. and the derived class of this class can no longer access this field.Methods and properties can also be set to private, which is also set to private and cannot be accessed by external and derived classes.This art
@+ adorner name. Indicates that the function is to be added when the adorner @add_strdef a (): Return ' 123 ' x = A () print XHello 123If the function that was added to the adorner itself would need to pass parametersFor exampledef a (m,n): Return ' 123 ' +m+nx = A (' 321 ', ' ABC ') print X123321ABCThen you only need to set two parameters in the adorner's inline function, so that the adorner can pass the required arguments of the original function into the adorner interior.def add_str (func):
Python training Day2Today, we mainly explain the common methods of int, float, str, list, tuple, and set classes. The difference between encode and decode. Regardless of the operating system character set. When they communicate with each other, they all need to convert the character set to Unicode, such as the universal code. In this way, there will be no barriers to communication between them. For example,
1, simple input/output interaction Input name=input (' hello,world! ') Output Print Hello world!2, the user enters two numbers, calculates and outputs the sum of two numbers: (try to do this with just one line of code)Enter the number x=input (' Please enter the first number: ') y=input (' Please enter the second number: ') sum sum=float (x) +float (y) to display the result print (' two number adds result:%.2f '%sum)3. Enter the radius to calculate the area of the circle.User input value r=inp
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.