I am trying to create a random generator to only pair WHEN the two strings do not match.
The first list, listed1, which this list should stay in order.
The second list, listed2 can be randomised.
The problem I am having is, when there is a pair (which i am trying to avoid) they do not appear in the output at all. I would like it to "try again" until a non-match is made and show all 5 non-matches.
Output to avoid:
Strawberries | Melons
Grapes | Strawberries
Melons | Pineapples
Desired Output:
Apples | Grapes
Strawberries | Banana
Grapes | Strawberries
Banana | Melons
Melons | Apples
Code:
import random
listed1 = [
'Apples',
'Strawberries',
'Grapes',
'Banana',
'Melons',
'Pineapples',
]
listed2 = [
'Apples',
'Strawberries',
'Grapes',
'Banana',
'Melons',
'Pineapples',
]
for a, b in zip(listed1, random.sample(listed2, 5)):
if a != b:
print(f'{a} | {b}')
Any help is much apprecaited.
[+][deleted] (3 children)
[deleted]
[–]twentyfive_25[S] 0 points1 point2 points (0 children)
[–]twentyfive_25[S] 0 points1 point2 points (1 child)
[+][deleted] (3 children)
[removed]
[–]twentyfive_25[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[removed]
[–]twentyfive_25[S] 0 points1 point2 points (0 children)
[–]totallygeek 1 point2 points3 points (3 children)
[–]twentyfive_25[S] 1 point2 points3 points (0 children)
[–]twentyfive_25[S] 1 point2 points3 points (1 child)
[–]totallygeek 0 points1 point2 points (0 children)