Word Cloud is popular in many web pages. Today, I find one simple way to generate word cloud by python. Here, we use pytagcloud package. It is can be find by Google.We used :python setup.py installto install this package in python2.7In the next, we
'''Created on 2013-1-29@author: Administrator'''def checkstreet(zhan, a): for i in zhan: if a==i: return 0 return 1 def dsf(a, b, zhan, street, street2): l = len(zhan) l2 = len(street2) if l==l2 and a==b:
'''Created on 2013-1-28@author: Administrator'''def count(tempr, number, station, i, order): train = [k for k in range(0,station)] for n in range(0,station): train[n] = 0 price = (tempr[i][1]-tempr[i][0])*tempr[i][2] a = tempr[i][0
文本的資訊很多,我們需要如何提取有用的資訊?比如一句話: Json is a good boy我們希望得到的資訊是json 和 a good boy那麼首先我們需要對句子進行分詞和判斷單詞的屬性:可以用下面的代碼:def ie_preprocess(document):... sentences = nltk.sent_tokenize(document) ... sentences = [nltk.word_tokenize(sent) for sent in sentences]
'''Created on May 20, 2013@author: Yang'''#Build the dictb = {}#intialize the dictb[1] = 2b[2] = 23b[4] = 25#b.keys()b.values()b.items()b.copy()b.get(1)b.get(3,2)b.has_key(5)if 1 in b: print 'yes'else: print 'no'if 1 not in b: print
Introductiondef() is the function which can be used to expose C++ functions and callable objects as Python functions in the current scope.這個函數可以協助我們將C++中的函數匯出到Python中,供Python使用。說實話,真的很好用。Functionsdeftemplate <class F>void def(char const* name,
以下是我的理解,如果有錯我的地方。請務必告訴我。不勝感激!在python語言裡,__str__一般是格式是這樣的。class A:def __str__(self):return "this is in str"事實上,__str__是被print函數調用的,一般都是return一個什麼東西。這個東西應該是以字串的形式表現的。如果不是要用str()函數轉換。當你列印一個類的時候,那麼print首先調用的就是類裡面的定義的__str__,比如:str.py#!/usr/bin/env
我曾經看過一段python 代碼。就是元類裡面的函數返回了一個類。我百思不得其解。為什麼要這麼做呢?通過調試我終於明白為什麼這麼做了。>>> class test(type):... pass... >>> class test1(test):... def fun (cls, count):... print count... >>> class test2(object):...