
a=[1,5,3,4,25,6]
和
b=[10,3]
现在我想要这种输出
b =[10,None,None]
为了得到这个输出,我使用了这个
for x,y in itertools.zip_longest(a,b):
但是,这对我没有帮助.我如何获得所需的输出?
after that I want give it size of a List,it doesn’t matter whether we add Zero or None,at the end I want the size of both of those List is the same
任何帮助将不胜感激.
解决方法 你很亲密你绝对可以使用zip_longest来获得你想要的输出:from itertools import zip_longesta = [1,6]b = [10,3][y for _,y in zip_longest(a,b)]# [10,None]
一个不同的选项,不会不必要地生成压缩对只是为了丢弃每个的一半将使用迭代器和下一个:
it = iter(b)[next(it,None) for _ in range(len(a))]# [10,None]总结
以上是内存溢出为你收集整理的在python中将元素添加到不相等的列表中全部内容,希望文章能够帮你解决在python中将元素添加到不相等的列表中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)