功能与两个列表中的参数 [英] Function with arguments in two lists

查看:98
本文介绍了功能与两个列表中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表xscat和yscat。我希望列表理解分别在xscat和yscat中选取x和y。结果列表应包含峰([x [0],y [0]]),峰([x [1],y [1]]) p>

  xscat = yscat = [ -  1,-1.5,5] 
[x(x,y) ,y in xscat,yscat]

你可以使用理解找到任何解决方案吗?或其他方式放置(地图)?

解决方案

zip 你想要什么:

  [zip(xscat,yscat)中的x,y的[(x,y))] b $ b  


I have two lists xscat and yscat. I would like the list comprehension to pick up x and y in xscat and yscat respectively. Resulting list should contain peaks([x[0], y[0]]), peaks([x[1], y[1]]) , etc

xscat=yscat=[-1, -1.5,5]
[peaks([x,y]) for x,y in xscat,yscat]

Can you find any solution using comprehensions ? or other ways to put it (map)?

解决方案

zip is what you want:

[peaks([x,y]) for x,y in zip(xscat,yscat)]

这篇关于功能与两个列表中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆