python如何做个单词查
绛旓細!/usr/bin/env python# coding: utf-8## author: Tim Wang# filename: baidu.py# date: Apr., 2014import redef top_ratios(context): words = [word.lower() for word in re.findall('\w+', context)] patt_vowel = re.compile('[aeiou]') onlyconsonant = [] ratios...
绛旓細!/usr/bin/env python dic={} for i in open('data.txt'):array=[]i=i.strip()array=i.split()for j in array:if not dic.has_key(j):dic[j]=0 dic[j]+=1 for i in dic.keys():print i,dic[i]
绛旓細import refrom collections import Counterfrom matplotlib.pyplot import pie,showf = 't.txt'c = Counter(re.findall(r'(\w{3,})',open(f).read().lower())).most_common(20)pie([i[1] for i in c],labels=[i[0] for i in c])show()
绛旓細浠ヤ笅鏄竴绉嶅彲鑳界殑璁$畻鏂规硶銆俿entence='''by: William Shakespeare From fairest creatures we desire increase,That thereby beauty's rose might never die,But as the riper should by time decease,His tender heir might bear his memory;But thou, contracted to thine own bright eyes,Feed'st ...
绛旓細杩斿洖瀹冨搴旂殑鏁存暟 绀轰緥锛>>> s = ord('a')>>> s 97 鏄庣櫧浜嗗惂锛屽氨鏄繑鍥炲崟瀛楃鍦ˋSCII涓搴旂殑鏁存暟 PS锛氭垜涔熸槸鍒氬python锛岃繖绉嶄笢瑗垮叾瀹炲ぇ鍙笉蹇呴棶浜猴紝瀵逛笉鏄庣櫧鐨勫嚱鏁扮洿鎺ュ湪IDLE涓暡鍏elp锛堜綘涓嶆槑鐧界殑鍑芥暟鍚嶏級灏卞彲浠ュ緱鍒扮浉搴旂殑璇存槑浜嗭紝涓嶆噦鐨鍗曡瘝鏌瀛楀吀锛岀劧鍚庢暡浠g爜瀹為獙 ...
绛旓細s="鎸囧畾瀛楃涓"f=open("鏂囨湰鏂囦欢鍚")n=int(raw_input("杈撳叆杈撳嚭鐨勮鏁:"))line=f.readline()while line: if s in line: print line for i in range(n): line=f.readline() if line: print line else: break if not line:break line=f.readline()
绛旓細浣跨敤姣旇緝鍩烘湰鐨勬柟娉曞啓鐨勫弬鑰冧唬鐮侊細!/usr/bin/env python# -*- coding: utf-8 -*-#python 2.7import reprint u'璇疯緭鍏ュ瓧绗︿覆锛'wz = raw_input()s = wz.lower()#灏忓啓鍗曡瘝鐨勬鍒欒〃杈惧紡r='[a-z]+'#鎵惧埌鎵鏈夊崟璇峸s = re.findall(r,s)#瀹氫箟涓涓瓧鍏告潵瀛樺偍鍗曡瘝鍜屾鏁癲t = {}for w ...
绛旓細123):letters.append(chr(i))#a-z num = 0 for i in string:if i in letters:#濡傛灉鏄瓧姣 num += 1 print(num)#杈撳嚭num 杩愯鏁堟灉锛6 澶囨敞锛氬姞绮楅儴鍒嗙殑鍗曡瘝鍙互鑷繁鏀广傝В鏋愶細閫氳繃ASCII鐮佸拰chr鍑芥暟鏌ユ壘鍒版墍鏈夊ぇ灏忓啓瀛楁瘝锛屽啀閫愪竴閬嶅巻鍗曡瘝锛屽鏋滄槸瀛楁瘝灏+1涓紝杩欐牱灏卞彲浠ュ緱鍒扮粺璁℃暟鎹簡銆
绛旓細鍙互浣跨敤urllib2搴擄紝浠ュ強re搴撴潵杩涜鍖归厤鏌ユ壘锛屼唬鐮佸涓嬶細import urllib2import reword = '浣犳兂鏌ユ壘鐨鍗曡瘝'urlfile = urllib2.urlopen('浣犺鎵撳紑鐨勭綉鍧鍐呭锛岃浣忚甯︿笂鍗忚鍓嶇紑锛屾瘮濡俬ttp') #浠ユ枃浠剁殑褰㈠紡鎵撳紑涓涓綉椤礹tml = urlfile.read() #浠庣綉椤垫枃浠朵腑璇籬tmlwordList = re.findall(re.compile...
绛旓細鐚滃崟璇 娓告垙 鏄竴绉嶇畝鍗曠殑 娓告垙 锛岃绠楁満浠庢寚瀹氬崟璇嶅垪琛ㄤ腑鎶藉彇涓涓崟璇锛岄氳繃绠楁硶锛屾妸鍗曡瘝鐨勫瓧姣嶉『搴忔墦涔憋紝鐒跺悗杈撳嚭缁欑帺瀹剁寽娴嬨傜帺瀹舵牴鎹贡搴忕殑瀛楁瘝锛岀粍鍚堢寽娴嬭緭鍏ユ纭殑鍗曡瘝銆傝绠楁満纭畾鏄惁鐚滄祴姝g‘銆備娇鐢ㄥ厓缁勬垨鍒楄〃鏋勫缓寰呯寽娴嬬殑鑻辨枃鍗曡瘝搴撳垪琛╓ORDS锛屼娇鐢╮andom妯″潡鐨刢hoice鍑芥暟浠庡崟璇嶇殑鍏冪粍涓殢鏈烘娊鍙栦竴涓嫳鏂...