Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17.0 lambda表达式 最后的例子-列表并行排序在python3中失效 #52

Closed
jay3zhang opened this issue Jun 20, 2017 · 1 comment

Comments

@jay3zhang
Copy link

jay3zhang commented Jun 20, 2017

列表并行排序,原来的代码

    data = zip(list1, list2)
    data.sort()
    list1, list2 = map(lambda t: list(t), zip(*data))

python3中报错:
AttributeError: 'zip' object has no attribute 'sort'

应该改为

    data = zip(list1, list2)
    data = sorted(data)
    list1, list2 = map(lambda t: list(t), zip(*data))

这是因为在python2中zip()返回的是list类型,而在python3中返回的是zip类型(一种可迭代类型),所以不能用sort(),而应该改为sorted()。

P.S. 原库 intermediatePython 目前也有这个问题

@suqi
Copy link
Contributor

suqi commented Jul 31, 2017

谢谢, 还把解决方案都拿出来了, 可以直接提PR的 👍

已改
933c9d2

@suqi suqi closed this as completed Jul 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants