I am trying to create a pseudo-random sequence generator. There are a couple of limitations, the first of which is that there must be 24 instances of each sequence and that there should never be a consistent occurrence of a sequence as a result. This is my code:
import random
def rgen():
block_list =[]
while len(block_list) != 96:
sequences = ['seq1','seq2','seq3','seq4']
block_list.extend(random.sample(sequences, 4))
for x,y in enumerate(block_list):
count = 'repeat'
while count == 'repeat':
if block_list[x] == block_list[x-1]:
block_list.pop(x)
block_list.extend(y)
count = 'repeat'
else:
count = 'no repeat'
sequence_counts = {'seq1':0,'seq2':0,'seq3':0,'seq4':0}
for i in block_list:
for k,v in sequence_counts.items():
if k == i:
v += 1
sequence_counts[k] = v
print 'counts for each sequence: ', sequence_counts
print block_list
The end result of this, however, is that at the end of the list I get something like this:
's', 'e', 'q', '1', 's', 'e', 'q', '1', 's', 'e', 'q', '2', 's', 'e', 'q', '4'
when I really want to just expand the entire list item, not individual characters.
so I want to expand all the lines that really are:
'seq1','seq1','seq2','seq4'