Time of Update: 2015-04-09
標籤:def TestDic1(): dict2 ={'aa':222,11:222} for val in dict2: print valdef TestDic2(): dict2 ={'aa':222,11:222} for (key,val) in dict2.items(): print key,":",val def TestList1(): list=[1,2,3
Time of Update: 2015-04-10
標籤:http://www.crifan.com/python_syntax_error_indentationerror/ 【問題】 一個python指令碼,本來都運行好好的,然後寫了幾行代碼,而且也都確保每行都對齊了,但是啟動並執行時候,卻出現語法錯誤: IndentationError: unindent does not match any outer indentation
Time of Update: 2015-04-06
標籤:python 字元轉換 類型轉換 報錯 python可以使用int(), float()等類型轉換函式實作類別型轉換的功能,特別是string類型轉換。 但是,我們也經常會發現報如下的錯誤:ValueError: invalid literal for int() with base
Time of Update: 2015-04-07
標籤:# -*- coding: utf8 -*-‘‘‘__author__ = ‘[email protected]‘55: Jump Gamehttps://leetcode.com/problems/jump-game/Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array
Time of Update: 2015-04-07
標籤:python fork exec 進程 並發 在python中,任務並發一種方式是通過進程分支來實現的.在linux系統在,通過fork()方法來實現進程分支.fork()調用後會建立一個新的子進程,這個子進程是原父進程的副本.子進程可以獨立父進程外運行.fork()是一個很特殊的方法,一次調用,兩次返回.fork()它會
Time of Update: 2015-04-03
標籤:今天要對一個1000個個記錄,每個記錄有n個屬性的文本進行聚類,採用的是二分k均值方法。演算法思想:我參考了Pang-Ning Tan資料採礦導論裡P317相對於kmeans的優點是不受其初始質心的影響。#coding utf-8#python 3.4#2015-4-3#Fitz Yin #yinruyi.hm@gmail.comfrom sklearn.cluster import KMeansimport numpy as npdef makedict(f):
Time of Update: 2015-04-03
標籤:function method Python中method的參數傳遞詳解 function就是可以通過名字可以調用的一段代碼,我們可以傳參數進去,得到傳回值。所有的參數都是明確的傳遞過去的。method是function與對象的結合。我們調用一個方法的時候,有些參數是隱含的傳遞過去的。下文會詳細介紹。instancemethod In [5]:
Time of Update: 2015-04-02
標籤: (體驗更好的閱讀效果,戳這裡) virtualenv virtualenv用於建立獨立的Python環境,多個Python相互獨立,互不影響,它能夠:1. 在沒有許可權的情況下安裝新套件2. 不同應用可以使用不同的套件版本3. 套件升級不影響其他應用 安裝 sudo apt-get install python-virtualenv 使用方法 virtualenv [虛擬環境名稱] 如,建立**ENV**的虛擬環境 virtualenv ENV
Time of Update: 2015-03-31
標籤:dp python leetcode Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at
Time of Update: 2015-03-29
標籤:chain(*iterables):原始碼:def chain(*iterables): for it in iterables: for element in it: &nbs
Time of Update: 2015-03-29
標籤:詞典類型 dict 字典由鍵(key)和對應值(value)成對組成。字典也被稱作關聯陣列或雜湊表。 dict 賦值 dict 整體放在花括弧{}中,每個鍵與值用冒號隔開(:),每對用逗號分割; d = {‘one‘:1, ‘two‘:2, ‘three‘:3} 鍵必須獨一無二,但值則不必;值可取任何資料類型,如字串,數或元組;若建立時同一個鍵被賦值兩次,後一個值會被記住; 鍵必須不可變,所以可以用數,字串或元組充當,用列表就不行 用 dict(
Time of Update: 2015-03-27
標籤:python kruskal 演算法 edge = [[1,2,1],[1,2,3],[1,3,2],[2,3,1],[2,4,4],[3,4,2]] #這是用邊集合表示的圖s = [[]]n = 4for i in range(n): s.append([i+1])#print s#compare方法是為了對邊排序寫的,作為參數傳入sort,就可以排序了def
Time of Update: 2015-03-20
標籤: Python的模組和包的概念:包中包含著模組,模組是以xxx.py格式儲存如果調用一個包代碼為import xxx。如果要指定調用包中的模組代碼為 import 包.模組。調用模組中的函數是一定要指明調用的路徑,包.模組.函數。 •匯入模組 要使用一個模組,我們必須首先匯入該模組。Python使用import語句匯入一個模組。例如,匯入系統內建的模組 math:import
Time of Update: 2015-03-20
標籤: #!/usr/bin/env python#coding: utf-8import smtplibfrom email.mime.text import MIMETextfrom email.header import Headersender = ‘[email protected]‘#receiver = ‘[email protected]‘receiver = ‘[email protected]‘subject = ‘python
Time of Update: 2015-03-19
標籤: Python是時下最熱門的程式設計語言之一了。簡潔而富有表達力的文法,兩三行代碼往往就能解決十來行C代碼才能解決的問題;豐富的標準庫和第三方庫,大大節約了開發時間,使它成為那些對效能沒有嚴苛要求的開發工作單位的首選;強大而活躍的社區,齊全的文檔,也使很多編程的初學者選擇了它作為自己的第一門程式設計語言。甚至有國外的報道稱,Python已經成為了美國頂尖大學裡最受歡迎的編程入門教學語言。 要學好一門程式設計語言實屬不易,在初學階段,就糾正一些錯誤的做法,對今後的深入學習至關重要。有一位
Time of Update: 2015-03-19
標籤:tcp socket python python可以利用socket庫實現通訊端編程。通訊端編程通常分為server端和client端,編程時一般是先server再client,這是最正常的邏輯,因為功能是由server提供的,client必鬚根據server提供的規則來建立串連和發送訊息。server端的函數:函數描述s.bind(addr
Time of Update: 2015-03-17
標籤:在學習的時候每次都會遺忘類,模組,函數到底首字母是大寫還是小寫,此文檔只供記憶使用,完整的命名規範請參考其他網路文檔例如:http://book.douban.com/reading/10700087/1.包,模組的命名規範全部小寫Filename:pythonmodule.py2.類,對象的命名規範每個單詞的首字母大寫,其他小寫class MyClass:3.函數首字母小寫,其他字母首字母大寫def myTest: python之命名規範
Time of Update: 2015-03-18
標籤:搭建Python環境:安裝Python包即可:Win版:https://www.python.org/ftp/python/2.7.9/python-2.7.9.msiLinux版:https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz使用虛擬環境:虛擬環境使用第三方工具virtualenv建立。檢查是否安裝了virtualenv: 1 $virtualenv
Time of Update: 2015-03-17
標籤:python 多線程 建立線程格式如下 threading.Thread(group=None, target=None, name=None, args=(), kwargs={})這個構造器必須用關鍵字傳參調用 - group 線程組 - target 執行方法 - name 線程名字 - args target執行的元組參數 - kwargs target執行的字典參數Thread對象函數 函數 描述
Time of Update: 2015-03-18
標籤:python 靜態程式碼分析工具 在python中安裝非內建python模組,有三種方式: easy_installpip下載壓縮包(.zip, .tar, .tar.gz)後解壓, 進入解壓縮的目錄後執行python setup.py