These days I design some algorithms in python, but find first two greatest value in python is too ugly and inefficient.
How to implement it in a efficient or a pythonic way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve found this to be consistently faster (about 2x for a list of 1,000,000 items) than
heapq.nlargest:(function modified at the suggestion of MatthieuW)
Here are the results of my testing (
timeitwas taking forever, so I usedtime.time()):