looping through multiple lists
map: 最大长度输出;
zip: 最短输出;
third: 有序排列;
a = ['a1', 'a2', 'a3']
b = ['b1', 'b2']
print "Map:"
for x, y in map(None, a, b):
print x, y
# will iterate 2 times,
# the third value of a will not be used
print "Zip:"
for x, y in zip(a, b):
print "{0}, {1}".format(x, y)
# will iterate 6 times,
# it will iterate over each b, for each a
# producing a slightly different outpu
print "List:"
for x, y in [(x,y) for x in a for y in b]:
print x, y
================= RESTART: /Users/vivi/Documents/multlist.py =================
Map:
a1 b1
a2 b2
a3 None
Zip:
a1, b1
a2, b2
List:
a1 b1
a1 b2
a2 b1
a2 b2
a3 b1
a3 b2
looping through multiple lists的更多相关文章
- Displaying SharePoint Lists or Libraries in other sites 显示其他站点的List
Child objects within SharePoint, like a list in a Site, share an inherent connection with that Paren ...
- notes: the architecture of GDB
1. gdb structure at the largest scale,GDB can be said to have two sides to it:1. The "symbol si ...
- MatterTrack Route Of Network Traffic :: Matter
Python 1.1 基础 while语句 字符串边缘填充 列出文件夹中的指定文件类型 All Combinations For A List Of Objects Apply Operations ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q45-Q48)
Question 45 You are designing a branding strategy for a customer with a new SharePoint 2010 server f ...
- Meet Python: little notes 2
From this blog I will turn to Markdown for original writing. Source: http://www.liaoxuefeng.com/ ♥ l ...
- Google上的Cookie Matching
Cookie Matching This guide explains how the Cookie Matching Service enables you to make more effecti ...
- Scala中Zip相关的函数
在Scala中存在好几个Zip相关的函数,比如zip,zipAll,zipped 以及zipWithIndex等等.我们在代码中也经常看到这样的函数,这篇文章主要介绍一下这些函数的区别以及使用. 1. ...
- underscore.js源码解析【数组】
// Array Functions // --------------- // Get the first element of an array. Passing **n** will retur ...
- Underscore.js(1.9.1) 封装库
// Underscore.js 1.9.1// http://underscorejs.org// (c) 2009-2018 Jeremy Ashkenas, DocumentCloud and ...
随机推荐
- iOS 三种打电话方式
//1,这种方法,拨打完电话回不到原来的应用,会停留在通讯录里,而且是直接拨打,不弹出提示 NSMutableString * str=[[NSMutableString alloc] initWit ...
- dnspython
dnspython 一个Python实现的一个DNS工具包,利用其查询功能来实现dns的服务监控及解析结果的校验. 安装 pip install dnspython 解析域名为IP from dns ...
- C++ 输出到文本文件
输出到文本文件 就像从文件输入数据一样,你也可以将数据输出到文件.假设你有一个矩阵,你想把结果保存到一个文本文件中.你会看到,将矩阵输出到文件的代码和将矩阵输出到终端的代码非常相似. 你需要在本地运行 ...
- 在ORACLE存储过程中创建临时表
在ORACLE存储过程中创建临时表 存储过程里不能直接使用DDL语句,所以只能使用动态SQL语句来执行 --ON COMMIT DELETE ROWS 说明临时表是事务指定,每次提交后ORACLE将截 ...
- Getting started with the basics of programming exercises_2
1.编写简单power函数 #include<stdio.h> int power(int m, int n); // test power function int main(void) ...
- win10如何关闭计算机设备和驱动器非硬盘图标
按win键+R,打开注册表regedit,找到这个路径: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\My ...
- 冒泡排序&直接插入排序&快速排序
一.冒泡排序 0 1 2 3 4 5 假设有一个6个数的数组,0,1,2,3,4,5是索引,冒泡排序就是相邻两个对比,比如5和4比,如果满足条件就互 ...
- 用户注册页的布局及js逻辑实现(正则,注册按钮)
文章地址:https://www.cnblogs.com/sandraryan/ 先写一个简单的静态页面,然后对用户输入的内容进行验证,判断输入的值是否符合规则,符合规则进行注册 先上静态页面 < ...
- 【C++竞赛 B】yyy的回文数组
时间限制:1s 内存限制:32MB 问题描述 回文串是一个正读和反读都一样的字符串,比如level或者noon就是回文串.回文数组也是如此,比如[100,200,100]或者[178,256,256, ...
- SSM整合 mybatis多条件查询与分页
多条件查询与分页: 通过页面的houseName.floorage获取值传到前端视图(HouseSearchVO)实体类中的houseName,floorage建立houseSearchVO对象. 通 ...