字典|字典和数组嵌套|keys()|value()|item()|del
python 中没有i++!
dic = {
'a':5,
'kelv':'ooo',
5:2333,
2333:'yoo'
}
print dic[dic[dic['a']]]
print dic
#yoo
#{'a': 5, 'kelv': 'ooo', 5: 2333, 2333: 'yoo'}
dic['sss']='ooooppppp'
print dic
#{'a': 5, 'kelv': 'ooo', 5: 2333, 'sss': 'ooooppppp', 2333: 'yoo'}
step=0
dic ['b']=5
for key,value in sorted(dic.items()):
print key,"\t",value
step=step+1
print "step is "+str(step)
'''
5 2333
2333 yoo
b 5
a 5
kelv ooo
sss ooooppppp
'''
del dic['kelv']
print dic
#{'a': 5, 'b': 5, 5: 2333, 'sss': 'ooooppppp', 2333: 'yoo'}
for k in set(dic.values()):
print k
'''
5
2333
ooooppppp
yoo
'''
new_1 = {'A':'asss','B':'bssss','C':'asss','D':'bssss'}
new_2 = {'lll':'asss',123:'bssss','A':'asss','B':'bssss','C':'asss','D':'bssss'}
new_3 = {'Appp':'asss','B':'bs'}
arr = [new_1,new_2,new_3]
for a in arr[:3]:
a['A'] = ''
a['D'] = 'lllllllll'
print arr
'''
[{'A': '1234', 'C': 'asss', 'B': 'bssss', 'D': 'lllllllll'}, {'A': '1234', 'C': 'asss', 'B': 'bssss', 'D': 'lllllllll', 'lll': 'asss', 123: 'bssss'}, {'A': '1234', 'B': 'bs', 'D': 'lllllllll', 'Appp': 'asss'}]
'''
print arr[1].keys()
print arr[1].items()
#['A', 'C', 'B', 'D', 'lll', 123]
#[('A', '1234'), ('C', 'asss'), ('B', 'bssss'), ('D', 'lllllllll'), ('lll', 'asss'), (123, 'bssss')]
for a in arr:
for k,v in a.items():
print k,"\t",v
'''
A 1234
C asss
B bssss
D lllllllll
A 1234
C asss
B bssss
D lllllllll
lll asss
123 bssss
A 1234
B bs
D lllllllll
Appp asss
'''
new_4={'kkkkk':{'opoppo':123}}
arr.append(new_4)
for value in arr[3].values():
for key2 in value:
print key2
#opoppo
字典|字典和数组嵌套|keys()|value()|item()|del的更多相关文章
- 记录我的 python 学习历程-Day05 字典/字典的嵌套
一.字典的初识 为什么要有字典 字典与列表同属容器型数据类型,同样可以存储大量的数据,但是,列表的数据关联性不强,并且查询速度比较慢,只能按照顺序存储. 什么是字典 先说一下什么叫可变与不可变的数据类 ...
- go实现json数组嵌套
go实现json数组嵌套 引用包 "encoding/json" 定义以下结构体 type person struct { Name string `json:"name ...
- js处理复杂数据格式数组嵌套对象,对象嵌套数组,reduce处理数据格式
let list=[ {id:1,name:'a'}, {id:1,name:'b'}, {id:1,name:'c'}, {id:2,name:'A'}, {id:2,name:'B'}, {id: ...
- Leetcode 565.数组嵌套
数组嵌套 索引从0开始长度为N的数组A,包含0到N - 1的所有整数.找到并返回最大的集合S,S[i] = {A[i], A[A[i]], A[A[A[i]]], ... }且遵守以下的规则. 假设选 ...
- localStorage中一个数组嵌套一个数组的怪相
localStorage中一个数组嵌套一个数组的怪相 需求:向本地存储中循环添加对象 思路 : 先完成点击事件中添加本地存储功能,当刷新时使用一个数组记录已经存储下来的数据,并在点击事件中将新生成 ...
- Java实现 LeetCode 565 数组嵌套(没有重复值的数组)
565. 数组嵌套 索引从0开始长度为N的数组A,包含0到N - 1的所有整数.找到并返回最大的集合S,S[i] = {A[i], A[A[i]], A[A[A[i]]], - }且遵守以下的规则. ...
- [VBS]脚本中的字典、动态数组、队列和堆栈
今天用VBS脚本写了几个程序,用到了字典(Dictionary).动态数组(ArrayList).队列(Queue)和堆栈(Stack).现在写篇Blog总结一下 :-) 1.编写环境 今天突发奇想下 ...
- swift基本用法-for循环遍历,遍历字典,循环生成数组
// Playground - noun: a place where people can play import UIKit //--------------------------------- ...
- swift-for循环遍历,遍历字典,循环生成数组
// Playground - noun: a place where people can play import UIKit //--------------------------------- ...
随机推荐
- 字符,字符串,int之间互相转换
字符转换成字符串:String str = String.valueOf(ch); 字符转换成int: int a = ch; 字符串转换成字符:char ch = str.charAt(0); 字符 ...
- python numpy 矩阵左右翻转/上下翻转
numpy API: flattened flip() (in module numpy) fliplr() (in module numpy) flipud() (in module numpy) ...
- SpringMVC_执行原理
什么是SpringMVC 概述 Spring MVC是Spring Framework的一部分,是基于Java实现MVC的轻量级Web框架. 查看官方文档:https://docs.spring.io ...
- 19 01 03 css 中 reset 模块 设置
主要就是让到时候 打入代码时候 把一些bug去除 或者 让一些固有的格式取消 /* 将标签默认的间距设为0 */ body,p,h1,h2,h3,h4,h5,h6,ul,dl,dt,form,i ...
- Python调用OpenCV读显写
OpenCV提供了python的接口,而且很重要的一点是python下的很多接口名与C++的接口名是一样的,这一篇先记录python调用OpenCV去读取图像.显示图像和保存图像. 1.OpenCV读 ...
- h5-web字体和字体图标
想要使用可以在: https://www.iconfont.cn/webfont?spm=a313x.7781069.1998910419.d81ec59f2#!/webfont/index :是we ...
- Q2:Add Two Numbers
2. Add Two Numbers 官方的链接:2. Add Two Numbers Description : You are given two non-empty linked lists r ...
- 字符串编码研究:Unicode
Unicode Unicode 编码系统可分为编码方式和实现方式两个层次. 1.编码方式 Unicode字符平面映射定义了所有的Unicode字符集. 2.实现方式(UTF8,UTF16) UTF-8 ...
- .NETCore部署步骤
1.下载.NET CORE运行时 下载地址:https://dotnet.microsoft.com/download 2.windows安装下载的运行时 3.检查.是否安装成功 ,dotnet -- ...
- 删除xcode项目中不再使用的图片资源
1. 利用工具 下载地址 http://jeffhodnett.github.io/Unused/ 运行效果如下 2. 通过终端 执行 shell 命令 a. 第一步建立.sh 文件 如 ...