find the minimum and maximum of the “nl10301” in python

If "nl10301" is a list, you can use the min and max functions to find the minimum and maximum values in the list, respectively:

main.py
nl10301 = [1, 2, 3, 4, 5]
minimum = min(nl10301)
maximum = max(nl10301)
72 chars
4 lines

If "nl10301" is actually a string that represents a list of numbers, you can convert it to a list using the eval function and then apply the min and max functions:

main.py
nl10301_str = "[1, 2, 3, 4, 5]"
nl10301 = eval(nl10301_str)
minimum = min(nl10301)
maximum = max(nl10301)
106 chars
5 lines

Note that using eval can be unsafe if you are parsing untrusted input, as it can execute arbitrary code. In that case, you should consider using a safer alternative like the ast.literal_eval function.

related categories

gistlibby LogSnag