如何获得“旧”在Python3中的zip() [英] How can I get the "old" zip() in Python3?

查看:165
本文介绍了如何获得“旧”在Python3中的zip()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Python 2.7迁移到Python 3.3,zip()不再像预期的那样工作了。
确实,我在文档中阅读它现在返回一个迭代器而不是一个列表。



那么我应该怎么处理这个?我可以在我的Python3代码中使用旧的zip()吗?



在Django项目中查找以前的工作原理:


$文件中的

in views.py: my_zipped_list = zip(list1,list2) .html: {{my_zipped_list.0.1}}



也许另一个解决方案是保持新 )行为和更改模板。



感谢您的帮助。

解决方案

通过执行列表(zip(...))来获取结果列表。


I migrated from Python 2.7 to Python 3.3 and zip() does not work as expected anymore. Indeed, I read in the doc that it now returns an iterator instead of a list.

So, how I am supposed to deal with this? Can I use the "old" zip() in my Python3 code?

Find bellow the way it worked before in a Django project:

in views.py: my_zipped_list = zip(list1, list2)

in file.html: {{ my_zipped_list.0.1 }}

Maybe another solution would be to keep "new" zip() behaviour and change template instead.

Thanks for help!

解决方案

Just make a list of the result by doing list(zip(...)).

这篇关于如何获得“旧”在Python3中的zip()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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