摘要:
转自:http://blog.csdn.net/business122/article/details/7536991 1 创建列表 2 sample_list = ['a',1,('a','b')] 3 4 Python 列表操作 5 sample_list = ['a','b',0,1,3] 6 7 得到列表中的某一个值 8 value_start = sample_list[0] 9 end_value = sample_list[-1] 10 11 删除列表的第一个值 12 del sample_list[ 阅读全文
posted @ 2014-02-05 23:42
cdsj
阅读(878)
评论(0)
推荐(0)
摘要:
转自:http://blog.csdn.net/business122/article/details/7537014 1 一.创建字典 2 方法①: 3 >>> dict1 = {} 4 >>> dict2 = {'name': 'earth', 'port': 80} 5 >>> dict1, dict2 6 ({}, {'port': 80, 'name': 'earth'}) 7 8 方法②:从Python 2.2 版本起 9 >& 阅读全文
posted @ 2014-02-05 23:41
cdsj
阅读(592)
评论(0)
推荐(0)
摘要:
转自:http://blog.csdn.net/business122/article/details/7541486 1 python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和sysmmetric difference(对称差集)等数学运算. 2 3 sets 支持 x in set, len(set),和 for x in set。作为一个无序的集合,sets不记录元素位置或者插入点。因此,sets不支持 indexing, slicin... 阅读全文
posted @ 2014-02-05 23:39
cdsj
阅读(661)
评论(0)
推荐(0)
摘要:
1 #统计词频,可以根据需要统计句子或文本 2 txt = 'this is a student there is a bag' 3 words = txt.split() 4 dict = {} 5 for w in words: 6 if w not in dict: 7 dict[w] = 1 8 else: 9 dict[w] = dict[w] + 110 print dict 阅读全文
posted @ 2014-02-05 10:02
cdsj
阅读(153)
评论(0)
推荐(0)

浙公网安备 33010602011771号