Dolamite Jenkins
asked on
return the highest number in the list
I need to iterate through my list and return the highest number in the list...
conn = lite.connect("PermPatRecord.sqlite")
c = conn.cursor()
c.execute('select * from ptrecords')
self.Ic_num = int(self.incident)
a=0
for i in c:
self.Ic_num = int(i[1])
print self.Ic_num
self.statusbar.SetStatusText("Incident# %s" % str(self.Ic_num+1),1)
a = 1
if a==0:
self.statusbar.SetStatusText("Incident# %s" % str(self.Ic_num),1)
self.num_ptct = 0
self.populate()
Why not use SQL when you already are using it
Follow this algorithm
Initialize max to first list element
Iterate through the rest of the list
If any list item is bigger than max
Set max equal to that item
Initialize max to first list element
Iterate through the rest of the list
If any list item is bigger than max
Set max equal to that item
You can also use max function on list
So if I have a list
[5,2,1,0,8,1]
max(_)
8
Or
L=[5,2,1,0,8,1]
Max=L[0]
for i in L:
if i > Max:
Max = i
Max
8
[5,2,1,0,8,1]
max(_)
8
Or
L=[5,2,1,0,8,1]
Max=L[0]
for i in L:
if i > Max:
Max = i
Max
8
ASKER
I appreciate your help but I am new.... because I loop through to get my list I am not putting it all together ... I apologize
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks