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

About the code on find_k_largest #233

Closed
ll0ruc opened this issue May 11, 2022 · 3 comments
Closed

About the code on find_k_largest #233

ll0ruc opened this issue May 11, 2022 · 3 comments

Comments

@ll0ruc
Copy link

ll0ruc commented May 11, 2022

n_candidates.sort(key=lambda d: d[1], reverse=True)

the n_candidates is the top K index and values. the candidates[0:K] will append two times in the for, so I think for iid,score in enumerate(candidates), the iid and score should skip the 0~K-1?

@Coder-Yu
Copy link
Owner

It doesn't. I just checked the code and printed the list. It works as expected. Why do you think it will append two times?

@ll0ruc
Copy link
Author

ll0ruc commented May 12, 2022

The for iid,score in enumerate(candidates means check the every value in candidates. While if the value is already in initial n_candidates and if the for, it will append one time again to the n_candidates. Just as the example find_k_largest(5, [1,2,3,4,5,6,7]). If the 0~K item in candidates is not the top K values, it will not affect the result.

@Coder-Yu
Copy link
Owner

if k_largest_scores[r] < score:

r=K-1 which means that for the first K items in candidates, the following codes conditioned on L146 would not be excuted. So, there would not be repeated items in the recommendation list.

However, it would be better if it iterates in the range [K:]. Thanks. I will consider to modify it.

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