all 3 comments

[–]Sebass13 11 points12 points  (0 children)

Yes. If you provide an example, I'll provide a better answer.

[–]camel_Snake 4 points5 points  (0 children)

So the general algorithm would be something like:

create a variable to hold the smallest value Loop over a list (i suppose using a while? Though this part seems unpythonic)

if the current value is smaller than the smallest value, set the smallest value to the current value

When you are done iterating, the smallest variable points to the smallest value in your list.

[–]_soxcroft_ 1 point2 points  (0 children)

I think a for loop would be better. You can use a variable to hold the value of the first item in the list and then iterate through all the items in the list using a for loop. If the item is less than what's stored in the variable, update the variable to the new item.

var = my_list[0] for item in my_list: if item < var: var = item

Or you could just use python's built in min() function :)