[Tutor] Bounded Linear Search
toganm at users.sourceforge.net
toganm at users.sourceforge.net
Sun Oct 16 15:18:29 CEST 2011
Hi,
I am trying to learn programming and python and one of the books I use has
an exercise for "Bounded Linear Search algorithm" under the heading in
Accumulating Unique Values at
<http://homepage.mac.com/s_lott/books/nonprog/html/p08_sequence/p08_c04_list.html#list-
exercises>
I have coded the exercises as below and what I can not figure it out is the
code works along as spin[0] and spine[-1] are not same but when it is the
code does not work. What am I missing ?
spin=[18, 10, 2, 19, 20, 10, 2, 7, 26, 10,2,2,18]
uniq=[]
for v in spin:
i=0
uniq.append(v)
while uniq[i]!=v:
i+=1
if uniq[i]==v:
if i!=len(uniq)-1:
uniq.pop(-1)
print(uniq)
Thanks
Togan
More information about the Tutor
mailing list