random / lists

wes weston wweston at att.net
Sun Aug 15 08:45:51 CEST 2004


Malcolm Clift wrote:
> Hi All,
> 
> I have this so far.
> 
> 
> 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
> 
> 

Calvin,
    Could you give a clear statement of what you want to
do. No code; just a description of what you want to do.
wes




More information about the Python-list mailing list