'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'modified', 'new', 'on_update', 'permanent', 'p...
分类:
其他好文 时间:
2015-08-03 16:10:12
阅读次数:
126
创建字典1. { }>>> dic={'name':'pmghong','age':'22','gender':'male'}>>> dic['name']'pmghong' 2. 使用工厂方法dict( )fdict=dict(['x',1],['y',2]) 3. 内建方法:fromkeys( ...
分类:
其他好文 时间:
2015-06-14 09:24:43
阅读次数:
117
def score(dices_input): count = {}.fromkeys(range(1, 7), 0) points = 0 for dice_side in dices_input: count[dice_side] += 1 # print ...
分类:
其他好文 时间:
2015-03-31 19:27:20
阅读次数:
114
list0=['b','c', 'd','b','c','a','a']方法1:使用set()list1=sorted(set(list0),key=list0.index) # sorted outputprint( list1)方法2:使用{}.fromkeys().keys()list2={}...
分类:
编程语言 时间:
2014-12-19 17:08:42
阅读次数:
208
a = [1,2,3,4,5,5,5,5,5,5,5]
c = set(a)
c = list(c)
b = {}.fromkeys(a,[0,0,0,0,0])
for x in c:
b[x][0] = a.count(x)
print b
猜猜会发生什么?
我猜python在执行程序的过程中,把a.count(x)当成一个常量来执行循环,把每个列表的第一个元素都变成了a.co...
分类:
编程语言 时间:
2014-11-26 22:39:15
阅读次数:
331
dict(dictionary)是一系列无序对象的集合,由键-值对构成,通过读取键来取得对应的值,具有可变,无序,异构,可嵌套的属性。dict初始化1、直接采用字典格式2、利用dict(),[注]:键没有加''3、利用tuple(元组)4、使用dict.fromkeys(),返回字典,该方法有两个参...
分类:
编程语言 时间:
2014-09-27 20:39:10
阅读次数:
321
字典:pytho中唯一映射类型,无序列表(哈希表)对象是可变的,但字典的键必须使用不可变对象,并且一个字典中可以使用不同类型的键值定义方法:-{}如:dic={name:‘zzc‘,age:19,gender:‘man‘}-使用工厂方法dict()列fdict=dice([‘x‘,1],[‘y‘,2])-内建方法:fromkeys()字典..
分类:
编程语言 时间:
2014-09-05 18:28:42
阅读次数:
253