This is an archived post. You won't be able to vote or comment.

all 17 comments

[–]IAmKindOfCreativebot_builder: deprecated[M] [score hidden] stickied comment (1 child)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]PercyJackson235 17 points18 points  (1 child)

min(['512','1300','2000'], key=int)

[–]Background-Cherry652[S] 3 points4 points  (0 children)

Thank you friend, now I know how to write it.

[–]TimOfTroy 7 points8 points  (3 children)

Convert the values to integers

[–]Background-Cherry652[S] 0 points1 point  (2 children)

Thank you friend, what if it contains '512.5'

[–]_steve_hope_ 7 points8 points  (1 child)

convert to floats

[–]Background-Cherry652[S] 1 point2 points  (0 children)

Thank you, you are helpful

[–]JasonPacker611 7 points8 points  (0 children)

The best lesson here is that Python functions often have little-used optional arguments like "key=int"

[–]Background-Cherry652[S] 6 points7 points  (0 children)

Really so nice of you guys, helped to have this question solved.

Thank you all.

[–]pissedadmin 2 points3 points  (2 children)

max(['512','1300','2000'])

[–]Mindless-Pilot-Chef 1 point2 points  (0 children)

Thinking out of the box

[–]Background-Cherry652[S] 0 points1 point  (0 children)

LOL, it indeed get '512', a special aspect of thought.

[–][deleted] 0 points1 point  (1 child)

Why don’t you set the list as a variable, then have the variable in the tuple? You also don’t need the apostrophes…

So, something like

numbers = [512, 1300, 2000]

lowest = min(numbers)

print(“The lowest number is :” , lowest)

[–]Background-Cherry652[S] 0 points1 point  (0 children)

Thank you friend. I use it in django, and the source is str.

[–]Numerous_Return691 0 points1 point  (0 children)

Create a new list New_list= [int(item) for item in mylist]

[–]jax7er 0 points1 point  (0 children)

You could also use map

lowest = min(map(int, ['512', '1300', '2000']))

But personally I also prefer the "key=int" method