Quick question, which is more efficient for finding the smallest number (float) in a long list (10000+ elements)
is it
min(mylist)
or
mylist.sort()
and then returning
mylist[0]
or something else…
thanks!
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.
If the list is already populated,
min()is the most efficient way.There are some tricks you might use in special scenarios:
O(1).min(). Make sure you understand the effects, mainly a slower insertion. (credit: interjay)