码迷,mamicode.com
首页 >  
搜索关键字:def    ( 28626个结果
一天一段scala代码(八)
一天一段scala代码(八)        为了更好的驾驭spark,最近在学习scala语言特性,主要看《快学scala》,顺便把一些自己认为有用的代码记下来。 package examples class Person8 { var name:String="" def this(name:String) {...
分类:其他好文   时间:2015-02-15 18:09:22    阅读次数:128
【文本挖掘】模拟退火英文分词
大概原理是找到文本中重复项最多的文本作为词典,代价函数为词典的累计词长和文本分词数之和,迭代找到代价函数最小值所对应的词典和分词结果。方法简单,跑出来的结果也挺有意思。 1 from random import randint 2 3 4 def segment(text,segs): 5 ...
分类:其他好文   时间:2015-02-15 14:56:37    阅读次数:155
Python 踩坑之嵌套函数
这里需要特别注意一下, Python是解释类型的语言. 会允许在定义A函数之前没有定义B函数的情况下,函数A调用函数B.def func1(): print "Hello fun1" fun2()def func2(): print "Hello func2"fun1()这样做是可以的.但是试想一下, 如果函数2也调用函数1呢?如下:def func1(): prin...
分类:编程语言   时间:2015-02-15 06:11:42    阅读次数:204
bs+json解析
# -*- coding=utf-8 -*- import urllib2 from BeautifulSoup import BeautifulSoup as bs3 import json import codecs #字符检测,用来检测其真实的编码格式 import chardet #save content to file def save_to_file(filename, co...
分类:Web程序   时间:2015-02-14 23:51:34    阅读次数:333
beautifulsoup学习-抓取页面并解析
以汽车之家为例子,抓取页面并进行解析 # -*- coding=utf-8 -*- import urllib2 from BeautifulSoup import BeautifulSoup as bs3 import json import codecs #字符检测,用来检测其真实的编码格式 import chardet #save content to file def save_...
分类:其他好文   时间:2015-02-14 17:35:13    阅读次数:178
学习python 快速排序
def q(start , end , a): if start>= end : return else : mid = (start+end)/2 i = start+1 j = end key =a[start] while i<j: while i<=end...
分类:编程语言   时间:2015-02-13 18:38:37    阅读次数:202
多进程和多线程
#!/usr/bin/python # -*- coding:utf-8 -*- import os import threading import multiprocessing import time #Process entry def process_worker(sign,lock,function): global count_process #lock.acquir...
分类:编程语言   时间:2015-02-13 18:31:28    阅读次数:172
python commands包不支持windows环境与如何在windows下使用的简易方法
commands模块不支持windows环境,让我们来看看。>>> import commands>>> print commands.getoutput('dir')'{' 不是内部或外部命令,也不是可运行的程序或批处理文件。>>> 查看commands.getoutput的源代码:def get...
分类:编程语言   时间:2015-02-13 18:20:03    阅读次数:131
煎蛋 无聊图解析
import requestsfrom html.parser import HTMLParserclass MyHtmlParser(HTMLParser): srclist = {} count = 0 def handle_starttag(self, tag, attrs)...
分类:其他好文   时间:2015-02-13 16:28:39    阅读次数:153
【转】Java精确四则运算
/** * 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。 */public class Arith { // 默认除法运算精度 private static final int DEF_DIV_SCALE = 10; // 这个...
分类:编程语言   时间:2015-02-13 16:28:07    阅读次数:168
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!