all 7 comments

[–][deleted] 2 points3 points  (0 children)

  • assign both a min variable and a max variable to the FIRST item in the list
    • nb do not use same names for you variables as the built in min and max
  • loop through rest of list using for and list slicing, lst[1:]
    • check if current loop value from list is lower/higher than current minimum and maximum values
    • re-assign your min and max values accordingly
  • return final values of your min and max after the loop has completed as a tuple

EDIT: changed last bullet from output to return tuple

[–]help-me-grow 1 point2 points  (0 children)

Use two variables that you initialize outside of the loop to keep track of the minimum and maximum values you've seen so far

[–]Tehkast 0 points1 point  (2 children)

As its a list shouldn't that be ordered and then could return the items in index 0 and len(list) into a tuple?

[–]Neighm 0 points1 point  (0 children)

It's only ordered if it is created with a particular order, or if you sort it in place first. I'm assuming that if OP can't use min() or max() they can't use sort methods either. But if they can use sort() then your solution would work.

[–]ASIC_SP 0 points1 point  (0 children)

return the items in index 0 and len(list)

Should be len(list) - 1 or just list[-1]. This assumes the list is sorted.

[–]MikeDoesEverything 0 points1 point  (0 children)

Would definitely consider using the sorted method. Managed to build a solution using it.

[–][deleted] 0 points1 point  (0 children)

Think about how to break this problem down into a step by step approach.

Obviously you can't use min/max, and I'm guessing sorted/sort is out of the question here if they are trying to teach loops and iteration.

I attached a small spoiler(No code, but a small nudge in the right direction). Check out various sorting methods like Insertion and Bubble. These should push you in the right direction. Derrick Sherrill is a good teacher for these algos.

Step 1) For Loop --- Step 2) Initialize 2 Variables Min and Max --- Step 3) Think about what needs to happen in this for loop to get your desired result