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

Python 3 issue fix - filter object has no attribute 'sort' #9

Open
Barqawiz opened this issue Feb 27, 2018 · 1 comment
Open

Python 3 issue fix - filter object has no attribute 'sort' #9

Barqawiz opened this issue Feb 27, 2018 · 1 comment

Comments

@Barqawiz
Copy link

Calling the function "apply_encoding_options" using Python3 raise following error:

AttributeError: 'filter' object has no attribute 'sort'

Reason:
Following two line cause the issue:
token_counts = filter(lambda x: x[1] >= min_token_count, token_counts) token_counts.sort(key=lambda x: x[1], reverse=True)
In python 3 filter function return object filter
In python 2.7 filter function return list (the code working correctly here)

Suggested Solution:
Edit function 'apply_encoding_options' inside 'processing.py' to order and filter without using filter object as following:
token_counts = sorted((x for x in token_counts if x[1] >= min_token_count), reverse=True, key=lambda x: x[1])

@mixwangw
Copy link

Thanks! It worked!

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