First.txtThe adjective Panada walked to the NOUN and then VERB. AnerbyNOUN was unaffected by these events.#!python3#-*- coding:utf-8 -*-#8.9.2疯狂填词游戏#用户自定义词语,修改打开文件中的ADJECTIVE、NOUN、VERBimport ref=open(‘first.txt‘,‘r+‘)files=f.read()print(files)f.close()changelist=[‘ADJECTIVE‘,‘NOUN‘,‘VERB‘]for i in changelist: change_reg=re.compile(r‘%s‘ % i) text=input("Enter a %s :" % i) files=change_reg.sub(text,files)fi_2=open(‘third.txt‘,‘w‘)fi_2.write(files)fi_2.close()"
#-*-coding:utf-8-*-# The required output is as follows:# apples Alice Dogs# dranges Bob Cats# cherries Carol Moose# banana David Goose tabledata=[[' apples ',' oranges ',' cherries ',' banana '],[' Alice ',' Bob ',' Carol ',' David '],[' Dogs ',' Cats ',' Moose',' goose '] def printtable(data): colwidths=[0]*len(data)For y in range(len(data[0])):For x in range(len(data)): if colwidths[x] Len(data[x] [y ]): colwidths[x]=len(data[x] [y]) For y in range(len(data[0])):For x in ra
(a) calculates the logarithm of matrix A.Np.linalg.norm (a,ord=none) #计算矩阵a的NormNp.linalg.cond (a,p=none) #矩阵a的condition numberNp.rNp.random.rand (3,2) #产生一个3行2列的 a random array. in the same space, there are several random functions such as RANDN ()/randint ()Np.roll (x,2) #roll () is a cyclic shift function. This call represents a 2-bit move to the right loop .Np.fFLIPLR ()/flipud ()/rot90 () #左右上下翻转, counterclockwise rotation 90-degree matrixNp.dNp.dot (A, b) to calculate the dot product of a
Best case: Time complexity O (NLOG2N)Worst case: Reverse sequence, time complexity O (n2)Average time complexity: O (NLOGN)Space complexity: O (NLOG2N)Stability: UnstableArray_test=[5,9,Ten,6,5, -, -,4, One,8]defQuick_sort (array, Low, high):ifLow>=HighreturnKey=Array[low] Start, end=Low, high whileLowHigh whileLowHigh andArray[high]>=Key:high-= 1 ifLowHigh:array[low]=Array[high] Low+= 1 whileLowHigh andArray[low]Key:low+= 1 ifLowHigh:array[high]=Arr
Transferred from: http://blog.csdn.net/sad_sugar/article/details/73743863System configuration: Windows10 x64, Visual Studio, Python2.7.1Error message: error:unable to find Vcvarsall.batCause of error: At the time of generation, the compiler%pythoninstallpath%\distutils\msvc9compiler.py 219 rows from the Find_vcvarsall (version) The Vcvarsall.bat file could not be found in the function.More specifically, msvc9compiler.py extracts the msvc version number from Sys.version, but the registry does not
Because of the recent intention to learn "machine learning combat" this book, so using Python may be used NumPy, matplotlib, scikit-learn These libraries, so the Internet to find how to install these libraries, look at a number of methods, after trying to find themselves very lucky, Soon it's done, and it's not complicated. Let's get down to business!
1, to the official website https://www.python.org/dow
Using Python for quick sortingIdea: Use each of the data in the list compared to the last one, the right side is bigger than the last, and the last one is left. Determine the last position first. It then recursively calls, sorting all the data from small to large.Code:defQuc (array,start,end):ifStart end:j=Quicly_sort (array,start,end) Quc (array,start,j-1) Quc (array,j+1, end)defQuicly_sort (array,start,en
Let me briefly introduce the two commonly used data structures, series and daraframe in Python, which are defined by the Pandas module. The series is similar to dict in Python, but is structured, and dataframe is similar to a table in a database.1.pandas basic data Structure-pandas. Seriespandas. DataFramethe second method of defining Dataframe cannot set index manually, only the sequence can be generated a
,path=timeself._path=/status/user/time ,path=list/status/user/time/list
Property does not exist, each time the __getattr__ method is called, the current Self._path + property name is returned, and is obtained by _path, accumulating until no attributePrint a value that returns Self._path__call__An object instance can be associated with its own properties and methods, and when we invoke an instance method, we use Instance.methond () to invoke it. Can be called directly on the instance its
When it comes to quick sorting, it really takes a lot of effort to see and understand. The sorting algorithm is quite complex, and understanding it is like peeling onions, one layer at a level. OK, let's talk about the principle of the fast-line.Fast sorting, like many online articles, is a divide-and-conquer, recursive way of constantly dividing and dividing. Each recursion will find the current benchmark value will be greater than this value of all
Catalog what is the three basic elements of the K-nearest neighbor algorithm model to construct KD tree search kd Tree python code (Sklearn Library)
what K-nearest neighbor algorithm (k-nearest neighbor,knn)
Cited examplesAssuming there is a dataset, where the first 6 are training sets (with attribute values and tags), we train a KNN model based on the training set to predict the movie type of the last movie.First, all the
typeAn ordered collection of arbitrary objects, which are accessed through an index, immutable objects, fixed lengthsSupports heterogeneous, nestedCommon operations:()(1,)(from)T1 + T2T1 * NInNot in:Although the tuple itself is immutable, modifications to such elements do not return tuples if they are nested inside a mutable type elementDictionary: DictDictionaries are also referred to as associative arrays or hash lists in other programming languageselement access by key, unordered set, mutabl
The basic idea of fast sorting: to find an element in an unordered list, with this element as the benchmark, all other elements are compared to the element, smaller than the element becomes a sub-sequence, larger than the element becomes another sub-sequence, and then repeat the process, and finally achieve the sorting effect. We also implement it in a recursive way.def quicksort (list): If Len (list) Return list Little = [] large = [] # take out the first element of the list
Start at both endsBased on the first, from the left, find the first one larger than the base number, then swapFrom left to right, find the first one that's better than the base number, then swapTraverse the left number of the remaining base numbers and the numbers to the right of the base number1 defQuick_sort (array,left,right):2 ifLeft >Right :3 return4 5Low = Left6High = Right7Key =Array[low]8 9 whileLeft Right :Ten whileLeft andArray[right] >Key: OneRight-= 1 AArra
#!python3#9.8.1#遍历目录树,查找特定扩展名的文件(自定义)#and把查找到的文件,copy到新文件夹import os,shutilfile_dir=input("输入要查找的目录:")file_dir=os.path.abspath(file_dir)file_list=[]if not os.path.exists(file_dir): print("目录不存在")else: file_type=input("输入要查找文件类型的扩展名(如.pdf或.jpg):") file_type=file_type.lower() for folder,subfolders,files in os.walk(file_dir): for fi in files: if fi.lower().endswith(file_type): file_list.append( os.path.join(folder,fi))#复制destination=input("输入要存放文件的目录:")destination=os.path.abspath(destination)if not
Fast sorting is fast, probably thinking is: First use a numeric value as the median, by first sorting the array into two parts, the left is smaller than this value, the right is larger than this value, and then use recursion to the two parts of the array to the same sort:1DefQuick_sort (Li, Start, end):2#Recursive end Condition:3If Start >=End4Return5#First Index on left6 left =Start7#The last index on the right8 right =End9#Take the first number as an intermediate valueTen mid =Li[left]11#First
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.