Advertisement
Guest User

code help

a guest
Jul 1st, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. from random import sample
  2.  
  3. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  4. prev_chars = ["", "", ""]
  5. stream = []
  6.  
  7. for _ in range(10):
  8.     chars = sample(alphabet, 3)
  9.  
  10.     # This while loop *should* ensure that there are no repeated letters in the same position in consecutive streams
  11.     #   (e.g. ['C', 'A', 'Y'] and ['C', 'R', 'X'])
  12.     flag = True
  13.     while flag:
  14.         # Set flag to false.  If the while loop needs to be run once more, it will be set to true later
  15.         flag = False
  16.  
  17.         # Iterate through the list of letters and previous letters
  18.         for char, prev_char in zip(chars, prev_chars):
  19.             # If the current letter is the same as the previous letter,
  20.             if char == prev_char:
  21.                 # Generate a new list of letters
  22.                 chars = sample(alphabet, 3)
  23.  
  24.                 # Set the flag to True so the while loop runs at least once more to check the most recent chars
  25.                 flag = True
  26.  
  27.                 # Break out of the for loop
  28.                 break
  29.  
  30.             # If the loop doesn't break, set the flag to False
  31.             # I suspect this is in the wrong place, but I'm not sure where to put it
  32.             #flag = False
  33.  
  34.     stream.append(chars)
  35.     prev_chars = chars
  36.  
  37. print(stream)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement