[Tutor] Bounded Linear Search

2011-10-16 Thread toganm
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


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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Bounded Linear Search

2011-10-16 Thread toganm
Peter Otten wrote:

> To verify that the algorithm is correct now you could walk through
> increasingly more complex sample data, which may be possible in this case,
> but rarely ever for an entire script. Instead the common approach is to
> pick a few samples along with the expected outcomes, feed them to your
> function and verify that they give the expected output
> 
> def unique_values(items):
>...
>return uniq
> 
> assert unique_values([42, 42]) == [42]
> assert unique_values([1, 2, 3, 2]) == [1, 2, 3]

Thanks for the tip and where I was failing to see

Togan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor