python zip dict函数
1.zip函数
zip函数可以接受多个参数,返回的结果是列表,列表中的每一个元素是元组的数据类型,下面我们通过几个例子来学习zip函数的用法
1)
list1 = [1,2,3]
list2 = [4,5,6]
list3 = [7,8,9]
zip(list1,list2,list3)
最后的返回的结果是:
[(1,4,7),(2,5,8),(3,6,9)]
2)
list1 = [1,2,3]
list2 = [4,5,6,7]
zip(list1,list2)
返回的结果是
[(1,4),(2,5),(3,6)]
上面的这个例子我们可以发现zip函数在字长上的处理
3)
list1 = [1,2,3]
zip(list1)
最后的返回结果是
[(1,),(2,),(3,)]
4)
zip()
最后的返回结果是[]
2.dict函数
dict函数用来快速构造字典,我们可以通过向dict函数传递不同的参数一不同的方式来创建字典,下面我们来了解一下几种常见的构造字典的方式
1)创建空字典
a = dict()#创建空字典
print(a)
结果
{}
2)传入关键字
b = dict(a=1,b=2,c=3)
print(b)
得到的结果是:
{"a":1,"b":2,"c":3}
3)传入一个字典:
c = dict({'three': 3, 'four': 4})
print(c)
结果
{'four': 4, 'three': 3}
4)传入可迭代对象
d = dict([('one', 1), ('two', 2), ('three', 3)])
print(d)
得到的结果是
{'three': 3, 'two': 2, 'one': 1}
python zip dict函数的更多相关文章
- Python 字典 dict() 函数
描述 Python 字典 dict() 函数用于创建一个新的字典,用法与 Pyhon 字典 update() 方法相似. 语法 dict() 函数函数语法: dict(key/value) 参数说明: ...
- python zip enumerate函数
zip是一个内置函数, 接受两个或多个序列,并将他们拉到一起,成为一个元组列表.每个元组包含各个序列中的一个元素. s = 'abc' t = [0,1,2] zip(s,t) >>> ...
- python的dict()函数
dict(one=1,two=2) dict({'one':1,'two':2}) dict((('one',1),('two',2))) dict((['one',1],['two',2])) di ...
- python 3 dict函数 神奇的参数规则
>>> dict({1:2},2=3)SyntaxError: keyword can't be an expression>>> dict({1:2},**{2: ...
- python中的 dict() 函数
Python 字典 dict() 函数用于创建一个新的字典,用法与 Pyhon 字典 update() 方法相似. dict() 函数函数语法: dict(key/value) 参数说明: key/v ...
- Python函数篇:dict函数和列表生成式
1.dict函数语法:dict()dict(**kwarg) dict(mapping, **kwarg) dict(iterable, **kwarg) 第一种:dict()构造一个空字典 h=di ...
- Python之路(第八篇)Python内置函数、zip()、max()、min()
一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算,如果全部都是true,就返回true, 但是如果是空字符串.空列表也返回t ...
- Python dict() 函数
Python dict() 函数 Python 内置函数 描述 dict() 函数用于创建一个字典. 语法 dict 语法: class dict(**kwarg) class dict(mappi ...
- Python之路Python内置函数、zip()、max()、min()
Python之路Python内置函数.zip().max().min() 一.python内置函数 abs() 求绝对值 例子 print(abs(-2)) all() 把序列中每一个元素做布尔运算, ...
随机推荐
- JavaScript match()方法和正则表达式match()
先介绍参数为普通字符串的使用方式,此时match方法的返回值是存放首次匹配内容的数组.如果没有找到匹配结果,返回null.语法结构: 1 str.match(searchvalue)参数解析:(1). ...
- Linux新手随手笔记1.1
ifconfig 查询网卡信息 分别是网卡名称,物理IP地址,MAC地址,RX收到数据包大小,TX发送数据包大小 # uname # uname -a 查看内核版本号 # hostname 查看主 ...
- Colorful Bricks CodeForces - 1081C ( 组合数学 或 DP )
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in t ...
- Spring Boot与消息
一.概述 1. 大多应用中,可通过消息服务中间件来提升系统异步通信.扩展解耦能力 2. 消息服务中两个重要概念: 消息代理(message broker)和目的地(destination) 当消息发送 ...
- Spring Boot 集成Swagger
Spring Boot 集成Swagger - 小单的博客专栏 - CSDN博客https://blog.csdn.net/catoop/article/details/50668896 Spring ...
- flutter Provide 状态管理篇
Provide是Google官方推出的状态管理模式.官方地址为: https://github.com/google/flutter-provide 现在Flutter的状态管理方案很多,redux. ...
- codeforces305A
Strange Addition CodeForces - 305A Unfortunately, Vasya can only sum pairs of integers (a, b), such ...
- 代理与hook
参考:Java 动态代理 代理是什么 为什么需要代理呢?其实这个代理与日常生活中的“代理”,“中介”差不多:比如你想海淘买东西,总不可能亲自飞到国外去购物吧,这时候我们使用第三方海淘服务比如惠惠购物助 ...
- [CIDR]calculate CIDR network capacity / 计算CIDR子网的网络容量
题目: 答案: 过程: 以B为例,192.168.9.140/27 /27 掩码是 8 8 8 111 00000 192.168.9.140是这个网段里的一个地址 140是 10001100 所以这 ...
- 洛谷 P4168 [Violet] 蒲公英
历尽千辛万苦终于AC了这道题目... 我们考虑1个区间\([l,r]\), 被其完整包含的块的区间为\([L,R]\) 那么众数的来源? 1.\([l,L)\)或\((R,r]\)中出现的数字 2.\ ...