Making different things equal

M. Clift noone at
Sun Aug 22 16:11:39 CEST 2004

Hi All,

Back again...

This code works nicely giving a list of names with no name repeated at a
space of 3 i.e. you won't get 'Bob','Bob' or 'Bob','Sue','Bob'.

What I'd like to do is add a condition to it which says that although the
names are different 'Bob' and 'Mary' are equal and so it won't generate
'Bob', 'Rita','Mary'

I've tried various ways to do it, but with no joy. Any help appreciated.

Thanks, M


from random import *

Name_Number = xrange(int(raw_input("Choose number of Names (1-20)? ")))

state = [None,None]

nextName = {'Bob':['Rita','Sue'],\

Name_List = []

tmp = choice(('Bob','Rita','Sue','Mary))

for x in Name_Number:
    print state
    while tmp in state[0:2]:
        tmp = choice(nextName[Name_List[-1]])
    print tmp, ", ",
    print "Name ",x+1," is ", tmp
    state[x%2] = tmp

    print Name_List


More information about the Python-list mailing list