Time of Update: 2015-05-13
標籤:演算法 python 二分尋找 搜尋 遞迴 在尋找方面,python中有list.index()的方法。<span style="font-size:14px;">>>> a=[2,4,1,9,3]
Time of Update: 2015-05-13
標籤:python endnote 檔案管理 endnote下載的檔案放在一個pdf檔案夾中的一堆亂序數位檔案夾中 現在老闆要求要把下載下來的檔案發給他, 但一個個拷出來感覺有些蛋疼,於是就想到了python,通過查閱資料,完美實現了這個整理的功能,果然是python大法好2333333333333最終效果: 本人python菜鳥,寫的不好的地方,請見諒#-------------------
Time of Update: 2015-05-12
標籤:演算法 格子乘法 阿拉伯乘法 大整數乘法 python 以前做ACM的時候,許多人都通過 BigInteger 來實現大數乘法,讓我記憶猶新的事2012年的遼寧省賽在大連大學,第一道水題就是大整數乘法,那時還不會java。 大數乘法的實現是基於印度的
Time of Update: 2015-05-12
標籤:一、安裝python,配置環境變數(根據python安裝路徑配置系統內容變數),我是安裝在(E:\Python27)二、下載py stuptools工具包--url: https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11.win32-py2.7.exe並自行安裝三、下載pip https://pypi.python.org/pypi/pip 四、安裝完成python和py stuptools後,將下載的py
Time of Update: 2015-05-11
標籤:不多說,直接上代碼client.py#!/usr/bin/pythonimport socket,sys,stringhost="localhost"port=8000def main(): sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect((host,port)) message = raw_input("please input whath you want to search:")
Time of Update: 2015-05-10
標籤: 1.模組格式#!/usr/bin/env python# -*- coding: utf-8 -*-.........if __name__==‘__main__‘:
Time of Update: 2015-05-10
標籤:#-*-coding:utf-8-*- #1、字典dict = {‘name‘: ‘Zara‘, ‘age‘: 7, ‘class‘: ‘First‘}#字典轉為字串,返回:<type ‘str‘> {‘age‘: 7, ‘name‘: ‘Zara‘, ‘class‘: ‘First‘}print type(str(dict)), str(dict)#字典可以轉為元組,返回:(‘age‘, ‘name‘, ‘class‘)print
Time of Update: 2015-05-10
標籤:python實戰 dict 字典 python實戰-字典使用使用字典統計字元出現次數#! /usr/bin/env python#coding:utf-8#定義一個函數,接收字串,統計出每個字元的出現次數#實現思路:字典實現,看字元是否在字典中,不在則計入字典,否則+1。def histogram(str): dic = dict() for c in str:
Time of Update: 2015-05-10
標籤:python語言的特點,簡潔,可讀性好。因此,以縮排作為代碼分界將是一種很好的方式。if語句,格式1:if expression1: if_suiteelse: else_suite格式2:if expression1: if_suiteelif: elif_suiteelse: else_suite while迴圈語句:格式:while
Time of Update: 2015-05-10
標籤: from selenium import webdriverimport timea=[] #建立一個空列表用於儲存查詢到的元素組driver = webdriver.Firefox()driver.get("http://mail.126.com/")#定位126郵箱標題上“ 免費郵|企業郵箱|VIP郵箱|國外使用者登入|學生使用者登入|手機用戶端|協助 | 線上答疑 ”a=driver.find_elements_by_
Time of Update: 2015-05-08
標籤:python os 模組刪除指定分類樹中的空目錄#!/usr/bin env pythonimport osimport sysdir =sys.argv[1]if os.path.isdir(dir): for root,dirs,files in os.walk(dir,topdown=False):#從最裡向外遍曆
Time of Update: 2015-05-09
標籤:# -*- coding: utf-8 -*- #把函數作為參數傳入,這樣的函數稱為高階函數,函數式編程就是指這種高度抽象的編程範式 #python內建map, reduce函數的用法 map(f, [x1, x2, x3, x4]) = [f(x1), f(x2), f(x3), f(x4)] map(lambda x,y: x+y, [1,1,1], [2,3,4]) reduce(f, [x1, x2, x3, x4]) = f(f(f(x1, x2), x3)
Time of Update: 2015-05-08
標籤:超連結 python 網頁 第 0009 題:一個HTML檔案,找出裡面的連結。思路:對於提取網頁中的超連結,先把網頁內容讀取出來,然後用beautifulsoup來解析是比較方便的。但是我發現一個問題,如果直接提取a標籤的href,就會包含javascript:xxx和#xxx之類的,所以要對這些進行特殊處理。0009.提取網頁中的超連結.py#!/usr/bin/env python#
Time of Update: 2015-05-08
標籤:python os 一、os模組概述Python os模組包含普遍的作業系統功能。如果你希望你的程式能夠與平台無關的話,這個模組是尤為重要的。 二、常用方法1、os.name輸出字串指示正在使用的平台。如果是window
Time of Update: 2015-05-08
標籤:#出處:http://www.cnblogs.com/QLeelulu/archive/2010/03/05/pyQuery.html#文檔:具體的PyQuery文檔見:http://pyquery.org/from pyquery import PyQuery as pqd=pq(‘<html></html>‘)#直接拼htmld=pq(url=‘http://www.qq.com‘)#開啟一個urlprint d(‘title‘)#擷取title元素print
Time of Update: 2015-05-06
標籤:#coding:utf-8import redef strip_tags(string, allowed_tags=‘‘): if allowed_tags != ‘‘: # Get a list of all allowed tag names. allowed_tags = allowed_tags.split(‘,‘) allowed_tags_pattern = [‘</?‘+allowed_tag+‘[^>]*>‘ for
Time of Update: 2015-05-07
標籤:2.第一個Django項目上一章節我們完成了python,django和資料庫等運行環境的安裝,現在我們來建立第一個django project吧,邁出使用django開發應用的第一步。2.1.建立第一個Django項目我們建立一個我們存放Django的工作目錄,樣本:C:\My Files\Python Projects 在命令提示字元視窗進入到剛才建立的目錄,運行運行命令:django-admin.py startproject
Time of Update: 2015-05-06
標籤:應用Webdriver,實現自動化 1 #coding:gbk 2 from selenium import webdriver 3 import os 4 5 from selenium.webdriver.support.ui import Select 6 base_url ="https://www.baidu.com" 7 chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.
Time of Update: 2015-05-12
python進階(資料結構和演算法[1])將序列分解為單獨的變數>>> p = (4,5) # 通過賦值分解元組或序列>>> x,y = p>>> x4>>> y5>>> data = ['ACME', 50, 91.9, (2000,1,1)]>>> name, shares, prices, date = data>>> name'ACME
Time of Update: 2015-05-12
python進階(資料結構和演算法[三]),python進階 在字典上將鍵映射到多個值上一鍵多值字典d = {'a':[1,2,3], 'b':[4,5]}e = {'a':{1,2,3}, 'b':{4,5}}可以使用from collections import defaultdict使用預設字典類,它的一個特點是自動初始化第一個值,後面只需要關注添加元素即可。from collections import defaultdictd = defaultdict(list)d['