Lists and tuples
zip is a built-in function that takes two or more sequence and ‘zips’ them into a list of tuples, where each tuple contains one element from each sequence.

The result is a list of tuples where each tuple contains a character from the string and the corresponding element from the list. If the sequences are not the same length, the result gets the length of the shorter one. You can use tuple assignment to traverse a list of tuples:

If you combine zip, for and tuple assignment, you get a standard idiom for traversing two (or more) sequences at the same time. For example, has_match takes two sequences, t1 and t2, and returns True if there is an index i such that t1[i] == t2[i]:

If you need to traverse the elements of a sequence and their indices, you can use the built-in function enumerate:

from Thinking in Python
Lists and tuples的更多相关文章
- python arguments *args and **args ** is for dictionaries, * is for lists or tuples.
below is a good answer for this question , so I copy on here for some people need it By the way, the ...
- [Python] 03 - Lists, Dictionaries, Tuples, Set
Lists 列表 一.基础知识 定义 >>> sList = list("hello") >>> sList ['h', 'e', 'l', ' ...
- Think Python - Chapter 12 Tuples
12.1 Tuples are immutable(元组是不可变的)A tuple is a sequence of values. The values can be any type, and t ...
- python 面试必读
总结了10道题的考试侧重点,供参考: 1.How are arguments passed – by reference of by value? 考的是语法,基本功,虽说python程序员可以不用关 ...
- 自然语言16.1_Python自然语言处理学习笔记之信息提取步骤&分块(chunking)
QQ:231469242 欢迎喜欢nltk朋友交流 http://www.cnblogs.com/undercurrent/p/4754944.html 一.信息提取模型 信息提取的步骤共分为五步,原 ...
- [Code::Blocks] Install wxWidgets & openCV
The open source, cross platform, free C++ IDE. Code::Blocks is a free C++ IDE built to meet the most ...
- Nemerle Quick Guide
This is a quick guide covering nearly all of Nemerle's features. It should be especially useful to a ...
- The Python web services developer: XML-RPC for Python
原文地址:http://www.ibm.com/developerworks/webservices/library/ws-pyth10/index.html 摘要:概括地说,您可以将 XML-RPC ...
- python27读书笔记0.3
#-*- coding:utf-8 -*- ##D.has_key(k): A predicate that returns True if D has a key k.##D.items(): Re ...
随机推荐
- [Unit Testing] Configure the Angular CLI to use the Karma Mocha test reporter
Every Angular CLI generated project comes already with Karmapreinstalled as well a couple of executa ...
- 110_leetcode_Best Time to Buy and sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- JStorm中的并行( parallelismction )介绍
JStorm中的并行( parallelismction )介绍 JStrom中.一个计算任务通过多台机器使得计算分解为多个独立并行执行在集群内执行的任务(tasks).从而得到水平扩展. JStor ...
- dpdk l2fwd 应用流程分析
int MAIN(int argc, char **argv) { struct lcore_queue_conf *qconf; struct rte_eth_dev_info dev_info; ...
- 93.快速搭建Web环境 Angularjs + Express3 + Bootstrap3
转自:https://www.cnblogs.com/wawahaha/p/3946023.html 前言 Angularjs越用越顺手,不仅代码量比jQuery少很多,而且实现思路特别清晰,构建大型 ...
- Nginx访问VM虚拟机CentOS 7系统与本地Windows系统共享目录403
用VMware安装了CentOS7系统,并搭建了Nginx,MySQL,PHP的web项目运行环境,为了方便Windows本地主机进行程序调试把Windows本地项目目录共享到了虚拟机CentOS中的 ...
- vue keep-alive保存路由状态2 (高级用法,接上篇)
接上篇 https://www.cnblogs.com/wangmaoling/p/9803960.html 本文很长,请耐心看完分析. 4.高级用法,指定从什么组件进入才缓存,以及销毁缓存:先介绍我 ...
- sql server 查询某数据库中包含某字段的所有表格
场景:查询DNMes数据库中所有包含RFID字段的表名 sql语句: select object_name(id) objName,Name as colName from syscolumns wh ...
- windows共享如何重新登录,或用另外的用户登录
使用net use * /del 可以结束已有的所有连接,或net use \\192.168.1.10 /del可以结束指定连接.比如想重新登录共享的话,就用这个命令结束原来的连接,就可以重新登录 ...
- ZBrush雕刻生物小技巧
本教程主要学习如何使用ZBrush®3D图形绘制软件的工具和笔刷雕刻酷酷的生物造型,我们今天来看看在游戏.媒体和电视领域有着十几年丰富经验的3D角色艺术家Francis-Xavier Martins是 ...