目录:

1. python 相加字典所有的键值 (python sum all values in dictionary)

2. python 两个列表分别组成字典的键和值 (python two list serve as key and value for dictionary)

3. python 把字典所有的键值组合到一个列表中 (python get dictionary values to combine a list)

内容:

1. python 相加字典所有的键值 (python sum all values in dictionary)

https://stackoverflow.com/questions/4880960/how-to-sum-all-the-values-in-a-dictionary

d = {'a':1, 'b':2, 'c':4}
sum(d.values())
7

2. python 两个列表分别组成字典的键和值 (python two list serve as key and value for dictionary)

https://stackoverflow.com/questions/209840/convert-two-lists-into-a-dictionary

In [1]: layout_type = ['LTTextBox', 'LTFigure', 'LTImage', 'LTLine', 'LTRect']

In [2]: color = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (160, 32, 240)]

In [3]: draw_color = dict(zip(layout_type, color))

In [4]: draw_color
Out[4]:
{'LTFigure': (0, 255, 0), 'LTImage': (0, 0, 255), 'LTLine': (255, 255, 0), 'LTRect': (160, 32, 240), 'LTTextBox': (255, 0, 0)}

3. python 把字典所有的键值组合到一个列表中 (python get dictionary values to combine a list)

https://thispointer.com/python-how-to-create-a-list-of-all-the-values-in-a-dictionary/

In [205]: a = {'apple':2, 'banana':3, 'pear':5}

In [206]: a
Out[206]: {'apple': 2, 'banana': 3, 'pear': 5} In [207]: list(a.values())
Out[207]: [2, 3, 5]

4.

python 常用技巧 — 字典 (dictionary)的更多相关文章

  1. python数据类型:字典Dictionary

    python数据类型:字典Dictionary 字典是一种可变容器模型,可以存储任意类型对象 键是唯一的,但是值不需要唯一 值可以取任何数据类型,但是键必须是不可变的,如字符串,数字,元组 创建字典: ...

  2. python学习之字典(Dictionary)练习

    Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串.数字.元组等其他容器模型 字典中分为键值对 , key 类型需要时被哈希. value 类型可以是 字符串.数字.元组等其他容器模 ...

  3. Python常用数据结构-字典——2.1 字典方法 keys()

    python字典常用方法: keys()               #  获取所有的键 values()            #  获取所有的值 items()              #  获 ...

  4. python常用技巧

    1,关于tab键与4个空格: 由于不同平台间,tab键值设置有所区别,据相关介绍,官方在缩进方面推荐使用4个空格.方便起见,可设置tab自动转换为4个空格. 1.1在pycharm中:    通过fi ...

  5. python 常用技巧

    一.字符串与数值的转换 Python中字符串转换为数值: str_num = '99' num = int(str_num) 整型数转换为字符串: num = 99 str_num = str(num ...

  6. python常用技巧 — 杂

    目录: 1. 找到字符串中的所有数字(python find digits in string) 2. python 生成连续的浮点数(如 0.1, 0.2, 0.3, 0.4, ... , 0.9) ...

  7. python 常用技巧 — 列表(list)

    目录: 1. 嵌套列表对应位置元素相加 (add the corresponding elements of nested list) 2. 多个列表对应位置相加(add the correspond ...

  8. python 常用技巧 — 数组 (array)

    目录: 1. 数组每一行除以这一行的总数(numpy divide row by row sum) 2. 数组每一行或者每一列求平均 (python average array columns or ...

  9. #1 Python灵活技巧

    前言 Python基础系列博文已顺利结束,从这一篇开始将进入探索更加高级的Python用法,Python进阶系列文章将包含面向对象.网络编程.GUI编程.线程和进程.连接数据库等.不过在进阶之前,先来 ...

随机推荐

  1. JAVA 利用 jmc或jvisualvm 监控 本地或者远程JVM

    本地检测之间到$JAVA_HOME/bin 下的目录点击jmc 或者jvisualvm,然后选择你要监控的app 可是一般我们生产环境项目都是部署在远程,这个时候想要监控怎么办 1.监控tomcat ...

  2. Python中的"Special Method"

    The first thing to know about special methods is that they are meant to be called by the Python inte ...

  3. sublime text3 手动安装插件package control

    好久没写了,今天换了新电脑,先安装前端神器“sublime” 一,安装 下载sublime,官方网址:http://www.sublimetext.com/: 二.插件包安装( Package Con ...

  4. springBoot02- 配置文件读取测试

    1.照例登陆http://start.spring.io/ ,改个项目名(Artifact),然后下载导入Eclipse 2. 项目结构如下, 在pom中添加web依赖(不添加,就找不到RestCon ...

  5. VB.NET导出Excel 轻松实现Excel的服务器与客户端交换 服务器不安装Office

    说来VB.Net这个也是之前的一个项目中用到的.今天拿来总结下用途,项目需求,不让在服务器安装Office办公软件.这个也是煞费了一顿. 主要的思路就是 在导出的时候,利用DataTable做中间变量 ...

  6. oracle函数自治事务解决不能增改删的语句操作

    CREATE OR REPLACE FUNCTION SEQ3 (v_bname in VARCHAR2) return NUMBER is pragma autonomous_transaction ...

  7. 把 MongoDB 当成是纯内存数据库来使用(Redis 风格)

    基本思想 将MongoDB用作内存数据库(in-memory database),也即,根本就不让MongoDB把数据保存到磁盘中的这种用法,引起了越来越多的人的兴趣.这种用法对于以下应用场合来讲,超 ...

  8. spring boot 尚桂谷学习笔记08 Docker ---Web

    ------Docker------ 简介:Docker是一个开元的应用容器引擎,性能非常高 已经安装好的软件打包成一个镜像放到服务器中运行镜像 MySQL容器,Redis容器...... Docke ...

  9. WireShark 自带工具 editcap 和 text2pcap 配合完成改包操作

    一.拆包 首先声明这种方法比较复杂而且需要点技术水平,不建议菜鸟尝试(可以使用WireEdit编辑pcap包,不过要联网)其实在熟练这种方法后也可以很快的,但这种方法主要还是方便吧,不用下载其他什么软 ...

  10. select下拉框选中其中一个值

    function LoadList123() { var param = { action: "SelectShopType1"};//参数拼接 var Resultstr = & ...