[Tutor] Need help understanding output...
Alan Gauld
alan.gauld at btinternet.com
Thu Aug 12 02:23:24 CEST 2010
"Laurens Vets" <laurens at daemon.be> wrote
> next to each other. I came up with the following (Please ignore the
> fact that I'm trying to avoid an IndexError in a stupid way :)):
Others have answered your question.
I'll suggest that instead of using indexes its easier to just cache
the
last two values in variables - back1 and back2 say.
initialise them to values outside the range for the first two values
then the loop body becomes (in pseudo code)
x = random number
if x == back1 == back2: # a triple
print 'error'
else
back2,back1 = back1,x
append(x)
HTH,
Alan G.
More information about the Tutor
mailing list