dimanche 24 février 2019

if consecutive duplicates generate another list

How can I make sure that this list does not have consecutive letters? I do not want to eliminate them, that I know how to do, I want to just have them pseudorandomly arrange where there are 5 letters of each but the same letter does not appear in succession.

Thank you.

my code thus far:

import random 

kounter1 = [5,5,5,5]
kounter2 = [0,0,0,0]


list = []

boo = True
while boo:
        #keep going until the profile of counts in kounter1 and and 2 match 
r = random.random()

if r <0.25 and kounter2[0] < kounter1[0]:
    c1 = 'a'
    kounter2[0]+=1      
    list.append(c1)

elif kounter2[1] < kounter1[1]:

   c1 = 'b'
   kounter2[1]+=1

   list.append(c1)

elif kounter2[2] < kounter1[2]:
   c1 = 'c'
   kounter2[2]+=1

   list.append(c1)
elif kounter2[3] < kounter1[3]:

  c1 = 'd'
  kounter2[3]+=1
  list.append(c1)

if kounter1 == kounter2:
   boo = False

print(list)




Aucun commentaire:

Enregistrer un commentaire