control direction of list

C

Calvin79

Hi All,

I was given this in an earlier post by Satchit.


import random

things = xrange(int(raw_input("choose no of things (1-8)? ")))

state = [None,None]

l = []

for x in things:
tmp = random.choice('abcd')
print state
while tmp in state[0:2]:
tmp = random.choice('abcd')
print "choice ",x+1," is ", tmp
l.append(tmp)

state[x%2] = tmp

print 1

Could someone help in showing me how to control it like this? That if 'a'
is choosen it can only be followed by say b or d, if 'd' is choosen it can
only be followed by c or b etc... I can see how to do this after the list
has been generated with if statements, but that is impractical. As it is
at the moment it stop two of the same letters being given one after
another or the same letter occurring with only one space interviening.

Thanks,

Calvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top