the smallest number in Python

Asked 2 years ago, Updated 2 years ago, 11 views

If the string has a (4658") it is the smallest value How can I make a function that returns 4568?

python

2022-09-21 22:05

2 Answers

You can use it with min(map(int,"4658)).


2022-09-21 22:05

I think I'm asking a question about sorting. The small value eventually comes in the first place.

int(''.join(sorted('4658')))
sorted('4658') # ['4', '5', '6', '8'] Sorting each character.
'.join (['4', '5', '6', '8']) # Make the list a string '4568'.
int('4568') # Transform into an integer. 


2022-09-21 22:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.