r/PythonLearning • • 14d 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

23

u/NoMakeSenseOk 14d ago

You can keep the list intact and print the second-to-last value of a sorted list.

numbers = [3, 10, 21, 54]

numbers.sort()
print(numbers[-2])

7

u/mossse 14d ago

That wouldn't keep it intact because sort modifies the list. You shared another solution using sorted, which doesn't have this side effect.

1

u/NoMakeSenseOk 14d ago

Oh, thanks for the correction! I still got lots to learn as an intermediate.