E-COM-NET
首页
在线工具
Layui镜像站
SUI文档
联系我们
推荐频道
Java
PHP
C++
C
C#
Python
Ruby
go语言
Scala
Servlet
Vue
MySQL
NoSQL
Redis
CSS
Oracle
SQL Server
DB2
HBase
Http
HTML5
Spring
Ajax
Jquery
JavaScript
Json
XML
NodeJs
mybatis
Hibernate
算法
设计模式
shell
数据结构
大数据
JS
消息中间件
正则表达式
Tomcat
SQL
Nginx
Shiro
Maven
Linux
python字典
Python dictionary 字典
Python字典
(Dict)
Python字典
是可变的,是另一种容器类型,可以存储任何Python对象,包括其他容器类型的数量。
ywjun0919
·
2013-03-25 09:00
python学习笔记:字典
python字典
的主要属性如下:1、通过键而不是偏移量来读取: 字典有时又被
1594cqb
·
2013-03-24 17:31
python
python笔记
python学习笔记:字典
python字典
的主要属性如下:1、通过键而不是偏移量来读取:字典有时又被称作关联数组(
1594cqb
·
2013-03-24 17:31
python
python笔记
python
[
Python字典
]根据字典的值查询出对应的键——实例
执行效果图:代码:#!/usr/bin/envpython #-*-encoding:utf-8-*- ''' 根据值查询对应的键 ''' key_list=[] value_list=[] mydisc={'key1':'123','key2':'234','key3':'345'} forkey,valueinmydisc.items(): key_list.append(key) value
lhyhr
·
2013-03-20 10:00
[转]
python字典
排序
1、准备知识:在python里,字典dictionary是内置的数据类型,是个无序的存储结构,每一元素是key-value对:如:dict={‘username’:‘password’,‘database’:‘master’},其中‘username’和‘database’是key,而‘password’和‘master’是value,可以通过d[key]获得对应值value的引用,但是不能通过v
hjctty
·
2013-03-19 10:47
database
password
Dictionary
的
是
Python 排序
Python字典
按值排序、包含字典的列表按字典值排序的方法3.
zhaoyl03
·
2013-03-17 11:00
排序
python
分享字典的定义和操作
python字典
的特点:字典是无序的,它不能通过偏移来存取,只能通过键来存取。字典 = {'key':value} key:类似我们现实的钥匙,而value则是锁。
m4774411wang
·
2013-03-16 20:00
分享
python字典
学习
1、字典的使用某些情况下,字典比列表更加适用,比如:表征游戏棋盘的状态,每个键都是由坐标值组成的元组;存储文件修改次数,用文件名作为键;数字电话/地址簿。假如有一个人名列表如下:>>>names=['Alice','Beth','Cecil','Dee','Earl']一个电话号码的列表如下:>>>numbers=['2341','9102','3158','0142','5551']建立了这些列
qiqijianglu
·
2013-02-23 10:00
遍历
python字典
几种方法
字典的关键字参数,可以省略key的引号,针对字符串 >>>dict(one='1',two='2') {'two':'2','one':'1'} 遍历
python字典
几种方法遍历dict的时候,养成使用
my2010Sam
·
2013-01-22 13:00
[置顶]
python字典
字典又称为关联表,是一种由键映射到值的数据结构,具有查找时间是常数的性能一个字典条目的语法格式是键:值。而且,多条字典条目被包含在({})里。1.创建字典和给字典赋值 wordcount={"hello":10,"world":32} 多从赋值,同时给多个字典赋值 (wordcount1,wordcount2)=({"hello":10,"world":32},{"world":12}) 使用内建
lldustc
·
2012-12-29 22:00
python
python
python内置函数sorted排序用法
关键字: python列表排序
python字典
排序sorted List的元素可以是各种东西,字符串,字典,自己定义的类等。
yidangui
·
2012-12-18 10:00
Python字典
应用的一个例子
#!/usr/bin/envpython #定义一个空字典 db={} defnewuser(): prompt='--logindesired:' whileTrue: name=raw_input(prompt) #根据关键字name看字典中是否已存在此键值对 ifdb.has_key(name): pro
buaa_shang
·
2012-12-14 20:00
python字典
排序
dic={'a':31,'b':5,'c':3,'d':4,'33':56,'d':0}想把dic的value按照从大到小排序(value都是整数)。写法如下:sorted(dic.iteritems(),key=lambdad:d[1],reverse=False)呵呵,看了是不是觉得有点晕?没关系。慢慢来。先看lambda函数是什么意思?>>>f=lambdax:x+1>>>f(2)3很简单了
jophyyao
·
2012-11-25 19:00
python
python
python字典
和集合
1. 字典字典是python中唯一的映射类型,采用键值对(key-value)的形式存储数据。python对key进行哈希函数运算,根据计算的结果决定value的存储地址,所以字典是无序存储的,且key必须是可哈希的。可哈希表示key必须是不可变类型,如:数字、字符串、只含不可变类型元素的元组(1,2,3,’abc’)、实现__hash__()方法的自定义对象(因为__hash__(
lover007
·
2012-11-16 12:03
集合
python
字典
python字典
和集合
1. 字典字典是python中唯一的映射类型,采用键值对(key-value)的形式存储数据。python对key进行哈希函数运算,根据计算的结果决定value的存储地址,所以字典是无序存储的,且key必须是可哈希的。可哈希表示key必须是不可变类型,如:数字、字符串、只含不可变类型元素的元组(1,2,3,’abc’)、实现__hash__()方法的自定义对象(因为__hash__()须返回一个整
AIOPS_DBA
·
2012-11-16 12:03
字典
集合
python
Python
Python字典
-微型数据库:当list不好用时使用dict吧
映射:映射可使用任何不可变对象表示元素,最常用的类型为字符串和数组,Python唯一内建的映射类型是字典。可通过在格式化说明符中包含名称(键)来对字典应用字符串格式化操作,挡在字符串格式化中使用元组时,有必要对元组的每个元素都设定“格式化说明符”,而使用字典时所用的格式化说明符要更少。字典的方法很多,调用的方式与调用列表和字符串的方法类似。在某些情况下,字典列表更实用:标记游戏棋盘的状态,每个键都
·
2012-09-21 12:00
python
python字典
和集合
1.字典字典是python中唯一的映射类型,采用键值对(key-value)的形式存储数据。python对key进行哈希函数运算,根据计算的结果决定value的存储地址,所以字典是无序存储的,且key必须是可哈希的。可哈希表示key必须是不可变类型,如:数字、字符串、只含不可变类型元素的元组(1,2,3,’abc’)、实现__hash__()方法的自定义对象(因为__hash__()须返回一个整数
zhoujianghai
·
2012-09-14 00:00
python
object
File
Integer
存储
Class
Django------The template 模版高级进阶1 2012.08.30
Context是一个传递给模版的名称到值的映射,类似
python字典
。 模版渲染就是通过从context获取值来替换模版中变量并执行所有的模版标签。
·
2012-08-30 20:00
template
python官方文档
docs.python.org/library/index.htmlDiveIntoPythonhttp://woodpecker.org.cn/diveintopython/toc/index.html
python
uestcyao
·
2012-08-28 13:00
python学习总结六(
python字典
)
一.字典是python语言中唯一的映射类型,映射哈希值(键key):指向对象(值value)。是一对多的关系。1.1创建字典和给字典赋值创建一个字典只需要把字典赋值给一个变量,不管这个字典包含不包含元素。>>> dict = {} >>> print dict {} 逐一赋值: >>> dict[1] = "a" >>> dict[3] = 3.13 >>> dict['houzaicun'] =
houzaicunsky
·
2012-08-16 15:46
python
学习
python学习总结六(
python字典
)
一.字典是python语言中唯一的映射类型,映射哈希值(键key):指向对象(值value)。是一对多的关系。1.1创建字典和给字典赋值创建一个字典只需要把字典赋值给一个变量,不管这个字典包含不包含元素。>>> dict = {}>>> print dict{}逐一赋值:>>> dict[1] = "a">>> dict[3] = 3.13>>> dict['houzaicun'] = 15600
houzaicunsky
·
2012-08-16 15:46
学习
python
Python
Python字典
的应用详解
字典一.创建字典方法①:>>>dict1={}>>>dict2={'name':'earth','port':80}>>>dict1,dict2({},{'port':80,'name':'earth'})方法②:从Python2.2版本起>>>fdict=dict((['x',1],['y',2]))>>>fdict{'y':2,'x':1}方法③:从Python2.3版本起,可以用一个很方便的
寂寞的远行者
·
2012-08-03 13:00
Python字典
排序及简单性能测试
字典是无序的键值对,但有时候需要对其排序。比较朴素的思路就是将字典转化为二元元组的列表,再sort。根据此博文http://www.kunli.info/2009/05/07/sorting-dictionaries-by-value-in-python/的介绍,最好的排序方法是PEP265http://www.python.org/dev/peps/pep-0265/(pythoncookboo
catmic
·
2012-07-24 08:10
排序
python
字典
Python字典
的应用详解[转载]
字典 一.创建字典 方法①: >>>dict1={} >>>dict2={'name':'earth','port':80} >>>dict1,dict2 ({},{'port':80,'name':'earth'}) 方法②:从Python2.2版本起 >>>fdict=dict((['x',1],['y',2])) >>>fdict {'y':2,'x':1} 方法③: 从Python2.3版
杨俊生
·
2012-07-17 13:00
python
字典
Python字典
按值排序、包含字典的列表按字典值排序的方法
#-*-encoding=utf-8-*-importoperator#按字典值排序(默认为升序)x={1:2,3:4,4:3,2:1,0:0}sorted_x=sorted(x.iteritems(),key=operator.itemgetter(1))printsorted_x#[(0,0),(2,1),(1,2),(4,3),(3,4)]#如果要降序排序,可以指定reverse=Trues
iteye_21281
·
2012-06-19 00:18
Python2.7
GhostFromHeaven
Pytho2.x
Python字典
按值排序、包含字典的列表按字典值排序的方法
#-*- encoding=utf-8 -*- import operator #按字典值排序(默认为升序) x = {1:2, 3:4, 4:3, 2:1, 0:0} sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1)) print sorted_x #[(0, 0), (2, 1), (1, 2), (4, 3
GhostFromheaven
·
2012-06-19 00:00
python
Python字典
按值排序、包含字典的列表按字典值排序的方法
#-*-encoding=utf-8-*- importoperator #按字典值排序(默认为升序) x={1:2,3:4,4:3,2:1,0:0} sorted_x=sorted(x.iteritems(),key=operator.itemgetter(1)) printsorted_x #[(0,0),(2,1),(1,2),(4,3),(3,4)] #如果要降序排序,可以指定rever
GhostFromHeaven
·
2012-06-19 00:00
python
list
lambda
encoding
遍历
python字典
几种方法
1.直接forin遍历keys2.调用函数,有:iteritems(),iterkeys(),itervalues(),iteritems(),iterkeys(),itervalues(),viewitems(),viewvalues(),viewkeys().......其中产生iter的有:iteritems(),iterkeys(),itervalues();产生list的有:iterit
索隆
·
2012-06-05 11:00
遍历
python字典
几种方法
aDict = {'key1':'value1', 'key2':'value2', 'key3':'value3'} print '-----------dict-------------' for d in aDict: print "%s:%s" %(d, aDict[d]) print '-----------item-------------'
GhostFromheaven
·
2012-06-03 19:00
python
GhostFromHeaven
dict遍历
python日志解析
Python字典
的setdefault()方法setdefault(key[,default])Ifkeyisinthedictionary,returnitsvalue.Ifnot,insertkeywithavalueofdefaultandreturndefault.defaultdefaultstoNone
th936
·
2012-05-29 15:21
apache
python
setdefault
python日志解析
Python字典
的setdefault()方法setdefault(key[,default])Ifkeyisinthedictionary,returnitsvalue.Ifnot,insertkeywithavalueofdefaultandreturndefault.defaultdefaultstoNone
th936
·
2012-05-29 15:21
apache
python
setdefault
python
Python字典
与集合操作总结
一.创建字典 方法①: >>>dict1={} >>>dict2={'name':'earth','port':80} >>>dict1,dict2 ({},{'port':80,'name':'earth'}) 方法②:从Python2.2版本起 >>>fdict=dict((['x',1],['y',2])) >>>fdict {'y':2,'x':1} 方法③:
business122
·
2012-05-05 10:00
c
工作
server
python
python学习(二)--- python列表排序
关键字: python列表排序
python字典
排序sorted List的元素可以是各种东西,字符串,字典,自己定义的类等。 sorted函
sunrise
·
2012-04-27 11:00
python字典
数组排序实现
python对容器内数据的排序有两种,一种是容器自己的sort函数,一种是内建的sorted函数。sort函数和sorted函数唯一的不同是,sort是在容器内排序,sorted生成一个新的排好序的容器eg数组排序: L=[5,2,3,1,4].sort:L.sort()sorted(...) sorted(iterable,cmp=None,key=None,reverse=False)--
liuzhoulong
·
2012-04-21 19:00
apple
Date
python
File
Collections
lambda
python中List的sort方法(或者sorted内建函数)的用法
关键字: python列表排序
python字典
排序 sorted List的元素可以是各种东西,字符串,字典,自己定义的类等。
gaopenghigh
·
2012-04-11 20:00
python
sorted
python字典排序
python列表排序
Python 字典的setdefault()方法
Python字典
的setdefault()方法setdefault(key[, default])If key isinthedictionary,returnitsvalue.Ifnot,insert
charlesdong1989
·
2012-04-09 10:00
4.
python字典
和None类型
例一:#-*-coding:UTF-8-*- a_dict={'chen':1,'jian':2}#创建一个字典 a_dict['chen']#通过key来访问 a_dict['chen']=3#修改字典 printa_dict a_dict['jian']=[4,5,6,7] printa_dict print'chen'ina_dict # #None
cjh6311882
·
2012-03-30 17:00
c
python
遍历
python字典
几种方法
脚本: #!/usr/bin/python dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print "
5iqiong
·
2012-03-14 22:55
职场
dict
字典
休闲
遍历
python字典
几种方法
脚本:#!/usr/bin/python dict={"a":"apple","b":"banana","o":"orange"} print "##########dict######################" for i in dict: print "dict[%s]=" % i,dict[i] print "###########items###########
5iqiong
·
2012-03-14 22:55
职场
字典
休闲
Python
PYTHON字典
常用函数
1.cleardict.clear()2.copya,b用的字典引用位置是相同的,aorb相互受对方影响所以有时候需要用到copyanddeepcopy函数a=b=dict1>b=a.copy()发生替换双方值不换相互影响,涉及新增删除会相互影响2>deepcopyfromcopyimportdeepcopyb=deepcopy(a)3.getdict.get('key','')4.has_key
bravezhe
·
2012-02-27 19:00
python
list
import
python字典
排序
程序中的解决办法: sorted(d.items(),key=lambda x:x[1]) links: http://blog.sina.com.cn/s/blog_85f5590f0100xutc.html sorted()是内建函数 help(sorted) Help on built-in function sorted in module
JohnnyMeng
·
2011-11-14 19:00
python
python字典
get函数陷阱
python字典
get函数有一个很微妙的陷阱,代码如下:>>>t={1:2}>>>s={3:4}>>>t.get(1,s[1])Traceback(mostrecentcalllast): File""
azhao_dn
·
2011-10-31 15:00
python
File
django背景变量的查找
比如,假设你要向模板传递一个
Python字典
Mr_JJ_Lian
·
2011-09-17 22:00
数据结构
c
django
python
import
Dictionary
Python中最快的字典排序方法
怎么让
Python字典
根据值快速排序.07年的时候,NICKGALBREATH在博客上发过一篇post postonsortingbyvalueatDigitalSanitationEngineering
gulang76
·
2011-07-25 14:00
python字典
之键值交换
>>>myDict={'a':'A','b':'B','c':'C'}>>>myDict{'a':'A','c':'C','b':'B'}>>>myDict={v:kfork,vinmyDict.items()}>>>myDict{'A':'a','C':'c','B':'b'}>>>
Cain
·
2011-06-29 16:00
c
python
python字典
排序
python字典
排序1、 准备知识:在python里,字典dictionary是内置的数据类型,是个无序的存储结构,每一元素是key-value对:如:dict = {‘username’:‘password
adermxl
·
2011-04-24 20:00
c
python
database
存储
lambda
Dictionary
python simplejson模块的使用方法
json化
python字典
数据: json.dumps(['foo', {'bar':
andylin02
·
2011-02-16 14:00
C++
c
json
python
C#
python 列表和字典的区别
如果把python列表 做为一种有序的对象集合类型的话,那
python字典
就是无序的集合类型,python 列表主要是根据偏移来取得存取,而
python字典
主要是根据键来存取。
m4774411wang
·
2010-05-24 22:00
python
python字典
基于键值映射, user1 = {}; user1['name'] = 'woxiaoe' user1['city'] = 'cs' user1['age'] = 1 print user1 user2 = {}; user2['name'] = 'yiba' user2['city'] = 'cs' user2['age'] = 1 ma
woxiaoe
·
2010-03-25 23:00
C++
c
python
C#
Python字典
的应用详解
字典 一.创建字典 方法①: >>> dict1 = {} >>> dict2 = {'name': 'earth', 'port': 80} >>> dict1, dict2 ({}, {'port': 80, 'name': 'earth'}) 方法②:从Python 2.2 版本起 >>> fdict = dict((
skyfen
·
2010-01-11 15:00
C++
c
python
C#
上一页
27
28
29
30
31
32
33
34
下一页
按字母分类:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
其他