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

90 Upvotes

58 comments sorted by

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()

1

u/RegularBother614 20d ago

I didn't know there's a list method of sort() 😂. I still have a lot to learn

1

u/Potential_Fix_5007 20d ago

Thats okay. Im still learning, too. Your way would donthe trick but you will lose the highest number, if you fine with that its a legit way to solve the problem.

1

u/RegularBother614 20d ago

Thanks! Can you recommend sources for me to learn more? It'll be really helpful

1

u/Potential_Fix_5007 20d ago

Sorry not really, i use AI to explain things to me and fumble me through my ideas, im not sure if that would be a good recommendation.

1

u/MarkRems 19d ago

The source I typically recommend beginners is "Automate the Boring Stuff with Python". It's free: https://automatetheboringstuff.com/