Gerard Flanagan wrote: > kpp9c wrote: > > > I have a question... and ... whew ... i am gonna be honest, i haven't > > the slightest clue how to even start ... i am not sure if i used up all > > my good will here or can take a mulligan.. i love to try to at least > > post some lame broken code of my own at first... but like i said, not > > being a math person i am not even sure how to start or if it is even > > possible. > > > > here's the deal... i have a dictionary that defines some collections.. > > like so: > > > > sets = { ('one') : [0, 4, 7, 9 ], > > ('two') : [0, 3, 7, 9 ], > > ('three') : [0, 4, 7, 11], > > ('four') : [0, 3, 7, 10 ], > > ('five') : [0, 4, 7, 10 ], > > ('six') : [0, 4, 8, 10 ], > > ('seven') : [0, 3, 6, 10], > > ('eight') : [0, 3, 6, 9 ], > > ('nine') : [0, 3, 7, 11 ], > > ('ten') : [0, 5, 7, 10 ] } > > > > I every time i call this function i would like like it to return a > > collection at random, any collection, so long as it has all but one > > element that is the same. So if i grab [0, 4, 7, 9 ] as my first set
> > # k is the length of the required output lists, 0<k<n > # n is the number of lists to output > > import random > > alphabet = [ 0, 3, 4, 5, 6, 7, 8, 9, 10, 11 ] > > def randomiser( a_list, n, k ): > d = len( a_list ) > choice = range(d) > vector = [] > for i in range(k): > vector.append( choice.pop(random.randint(0,d-i-1)) ) > yield [ a_list[s] for s in vector ] > #yield sorted( a_list[s] for s in vector ) > for _ in range(n): > rand_vector_idx = random.randint(0,k-1) > rand_choice_idx = random.randint(0,d-k-1) > rand_vector_val = vector[rand_vector_idx] #remember old value > vector[rand_vector_idx] = choice.pop( rand_choice_idx ) > choice.append( rand_vector_val ) #add old value back to choice > yield [ a_list[t] for t in vector ] > #yield sorted( a_list[t] for t in vector ) > Sorry, I realise this doesn't answer your question - it is the collections themselves which are your 'alphabet', not the set of their elements. Looks like it's Graph Theory for you! Apologies. Gerard -- http://mail.python.org/mailman/listinfo/python-list