I feel confused about the code as follows:
def findMin(alist):
overallmin=alist[0] #define this findmin function to find the smallest
number in alist,O(n^2)#
for i in alist:
issmallest= True
for J in alist:
if i>j:
issmallest= False
if issmallest:
overallmin = i
return overallmin
I can't understand: 1,why the author set "issmallest = True" in the first for loop, at the same time, I don't know why or how to use the boolearn value as the for or while loop condition directly. Another confusion is like " while True:" this kind of situation. why they want to set the boolean here as the condition?
Aucun commentaire:
Enregistrer un commentaire