如何获得“旧”在Python3中的zip() [英] How can I get the "old" zip() in Python3?
问题描述
确实,我在文档中阅读它现在返回一个迭代器而不是一个列表。
那么我应该怎么处理这个?我可以在我的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屋!