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 ...
随机推荐
- oracle loader
控制文件的格式 load data infile '数据文件名' into table 表名 (first_name position(01:14) char, sur ...
- Java练习 SDUT-2561_九九乘法表
九九乘法表 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 九九乘法表是数学学习的基础,今天我们就来看看乘法表的相关问题 ...
- 动态设置iframe高度
<%//动态设置iframe高度 %><script language="javascript" type="text/javascript" ...
- jQuery学习笔记之解除重复点击事情重复绑定
问题:有不同的按钮点击后都执行相同的事件,在jQuery重复点击就会产生事件重复绑定. 解决方法:使用unbind("click")方法,每次点击都先接触绑定已有事件再绑定新对象. ...
- Mac OSX原生读写NTFS功能开启方法
macOX系统内建的NTFS支持默认只能读不能写 原生读写NTFS,需要自行终端命令手动开启 1. 插上磁盘 此时Mac桌面应该会显示出插入的磁盘,但是当你想把文件拖入磁盘的时候,发现是不能拖进去的, ...
- 2018-8-10-win10-uwp-如何在DataTemplate绑定方法
title author date CreateTime categories win10 uwp 如何在DataTemplate绑定方法 lindexi 2018-08-10 19:16:50 +0 ...
- laravel 5 自定义全局函数,怎么弄呢?
在app/Helpers/(目录可以自己随便来) 下新建一个文件 functions.php 在functions.php 中加入这个方法 然后在 bootstrap/autoload.php 中添加 ...
- 测试代码的执行时间魔法方法%time和%timeit
对于规模更大.运行时间更长的数据分析应用程序,你可能会希望测试一下各个部分或函数调用或语句的执行时间.你可能会希望了解某个复杂计算过程中到底是哪些函数占用的时间最多.幸运的是,在开发和测试代码的过程中 ...
- 2018-10-19-Nuget-通过-dotnet-命令行发布
title author date CreateTime categories Nuget 通过 dotnet 命令行发布 lindexi 2018-10-19 09:15:53 +0800 2018 ...
- H3C 单区域OSPF配置示例二