r/PythonLearning • u/RegularBother614 • 20d ago
What do you guys think?
I made a program that finds the second largest digit in a list.
Using the list method "remove()" and "max" function. Python is COOL!
90
Upvotes
View all comments
3
u/Potential_Fix_5007 20d ago
Im not sure, but it would change your list, so it would be "numbers = [10, 3, 21]" So you "lost" the largest number. You could sort the list and print the second number from the end.
numbers = [10, 54, 3, 21] #your starting list numbers.sort() # sort list to [3, 10, 21, 54] print(numbers[len(numbers) - 2]) #create the correct index from len()