惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
P
Proofpoint News Feed
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
博客园_首页
I
InfoQ
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
美团技术团队
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research

RealCat

📝笔记:图像匹配挑战赛回顾(CVPR 2023) | RealCat 📝笔记:Stable Diffusion QR-Code | RealCat 📝笔记:图像匹配挑战赛回顾(CVPR 2022) | RealCat 📝笔记:5秒钟训练NeRF,NVIDIA Instant NeRF 测试 | RealCat 📝笔记:Visualization Localization Revisited(under construction...) | RealCat 📝笔记:使用vlfeat的Matlab接口简单实现BOW以及VLAD | RealCat 📝笔记:一些关于KD-Tree的知识点 | RealCat 📝笔记:简明矩阵求导术之分子布局与分母布局 | RealCat 📝笔记:使用Clockwise/Spiral Rule技巧轻松读懂变量/函数声明 | RealCat 🔨工具:优雅地下载Youtube视频 | RealCat 🔨工具:每日自动获取arXiv论文摘要 | RealCat 🎃资料: 从Eigen向量化谈内存对齐 | RealCat 📝笔记:图像匹配挑战赛总结 (SuperPoint + SuperGlue 缝缝补补还能再战一年) | RealCat 📝笔记:ICCV 2021最佳学生论文 | COLMAP 优化建图组件 Pixel-Perfect SFM | RealCat 📝笔记:CVPR 2021 | PixLoc: 端到端场景无关视觉定位算法(SuperGlue一作出品) | RealCat 📝笔记:港大MARS实验室 R3LIVE (R2LIVE升级) 鲁棒实时RGB雷达视觉惯导紧耦合状态估计 | RealCat 🔨工具:bash常用命令 | RealCat 📝笔记:VSLAM基础知识导图 | RealCat 📝笔记:Patch-NetVLAD论文阅读 | RealCat 📝笔记:光场相机能否用于SLAM? | RealCat 📝笔记:读写文本常用操作 | RealCat 📝笔记:CVPR 2020 视觉定位挑战赛冠军方案 | RealCat 📝笔记:三维重建系列 COLMAP: Structure-from-Motion Revisited | RealCat 🐈芒果驾到 | RealCat 📝笔记:GMS一种基于运动统计的快速鲁棒特征匹配过滤算法 | RealCat 🌡️秋天到了,还是很热 | RealCat 📝笔记:AdaLAM: Revisiting Handcrafted Outlier Detection 超强外点滤除算法 | RealCat 🔨工具:使用vercel加速Hexo静态博客访问 | RealCat 📝笔记:ORB-SLAM3论文阅读 | RealCat 🔨工具:解决Github挂图及龟速访问 | RealCat
📝笔记:Python zip() | RealCat
2022-11-05 · via RealCat

The zip() function takes iterables (can be zero or more), aggregates them in a tuple, and returns it.

举个例子:

languages = ['C++', 'Python']
versions = [2,6]

result = zip(languages, versions)
print(list(result))

# Output: [('C++', 2), ('Python', 6)]

zip() 函数的输入是多个迭代器对象,输出一个zip对象,它是一个tuple迭代器(iterator of tuples),将输入的迭代器中的每个元素一一配对;如果每个迭代器长度不一致,则其输出输入迭代器中最短的那个。

languages = ['C++', 'Python']
versions = [2,6,7,8,9]

result = zip(languages, versions)
print(list(result))

# Output: [('C++', 2), ('Python', 6)]

更多例子:

number_list = [1, 2, 3]
str_list = ['one', 'two', 'three']

# 0. No iterables are passed
result = zip()

# Converting iterator to list
result_list = list(result)
print(result_list)

# 1. One iterables are passed
result = zip(number_list)

# Converting iterator to list
result_list = list(result) #DO NOT equal [result]!!!
print(result_list)

# 2. Two iterables are passed
result = zip(number_list, str_list)

# Converting iterator to set
result_list = list(result)
print(result_list)

# 3. Two iterables are passed
result = zip(number_list, str_list)

# Converting iterator to set
result_set = set(result)
print(result_set)

输出:

[] #空列表中无元组
[(1,), (2,), (3,)] #列表中元组长度为1
[(1, 'one'), (2, 'two'), (3, 'three')] #列表中元组长度为2
{(1, 'one'), (2, 'two'), (3, 'three')} #字典中元组长度为2

另外,zip() 通常与 * 操作符联合使用,其中 * 操作符起到了解压的作用。

coordinate = ['x', 'y', 'z']
value = [3, 4, 5]

result = zip(coordinate, value)
result_list = list(result)
print(result_list)

c, v =  zip(*result_list)
print('c =', c)
print('v =', v)
print(*result_list)

输出:

[('x', 3), ('y', 4), ('z', 5)]
c = ('x', 'y', 'z')
v = (3, 4, 5)
('x', 3) ('y', 4) ('z', 5)