How do you get the smallest integer in a list without using the min() built-in function and also its index? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do you get the smallest integer in a list without using the min() built-in function and also its index?

1st Apr 2017, 2:11 AM
Kanra
Kanra - avatar
5 Answers
+ 9
Use a for loop to go through each element. Test if it is less than a variable "min." If it is, replace "min" with that number and continue until you have gone through all of the elements.
1st Apr 2017, 2:18 AM
J.G.
J.G. - avatar
+ 4
what J.G. said
1st Apr 2017, 2:46 AM
Aeedoom Aeedad
Aeedoom Aeedad - avatar
+ 3
for loop with "enumerate" function will help you get both min value and its index at the same time.
1st Apr 2017, 5:05 AM
Igor B
Igor B - avatar
0
nums = [23,18,45,2,9] x = sorted(nums)[0] print(x,nums.index(x))
2nd Apr 2017, 10:50 AM
richard
- 2
Implement a sort algorithm (quick sort, bubble sort, binary sort)
1st Apr 2017, 2:25 AM
Dago VF
Dago VF - avatar