一天一段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是解释类型的语言. 会允许在定义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
# -*- 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
以汽车之家为例子,抓取页面并进行解析
# -*- 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
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
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的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 确的浮点数运算,包括加减乘除和四舍五入。 */public class Arith { // 默认除法运算精度 private static final int DEF_DIV_SCALE = 10; // 这个...
分类:
编程语言 时间:
2015-02-13 16:28:07
阅读次数:
168