r/PythonLearning • • 13d ago

What do you guys think?

Post image

I made a program that finds the second largest digit in a list.

Using the list method "remove()" and "max" function. Python is COOL!

88 Upvotes

58 comments sorted by

View all comments

Show parent comment

3

u/Vigintillionn 13d ago

well, to be honest, their solution is more efficient being O(3n) ~ O(n) while yours is O(nlogn). Not that it makes much of a difference, for small lists O(nlogn) might even beat theirs but asymptotically theirs is more efficient

1

u/max96t 12d ago

I agree. The best would probably be using the builtin heapq.nlargest function ( which is O(n))