Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import sample
- alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- prev_chars = ["", "", ""]
- stream = []
- for _ in range(10):
- chars = sample(alphabet, 3)
- # This while loop *should* ensure that there are no repeated letters in the same position in consecutive streams
- # (e.g. ['C', 'A', 'Y'] and ['C', 'R', 'X'])
- flag = True
- while flag:
- # Set flag to false. If the while loop needs to be run once more, it will be set to true later
- flag = False
- # Iterate through the list of letters and previous letters
- for char, prev_char in zip(chars, prev_chars):
- # If the current letter is the same as the previous letter,
- if char == prev_char:
- # Generate a new list of letters
- chars = sample(alphabet, 3)
- # Set the flag to True so the while loop runs at least once more to check the most recent chars
- flag = True
- # Break out of the for loop
- break
- # If the loop doesn't break, set the flag to False
- # I suspect this is in the wrong place, but I'm not sure where to put it
- #flag = False
- stream.append(chars)
- prev_chars = chars
- print(stream)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement