The list comprehension below achieves the desired result/output:
- Each tuple in the list is indexed sequentially
- The names are grouped together by suit
- The names are in a consistent order
Code (deck of cards toy example):
Suits = ["Hearts"]*3 +["Diamonds"]*3
Names = ["Two","Ten","King"]
z = [(i,Names[(i-1)%3],Suits[((i-1)%6)]) for i in range(1,7)]
Output z:
[(1, 'Two', 'Hearts'),
(2, 'Ten', 'Hearts'),
(3, 'King', 'Hearts'),
(4, 'Two', 'Diamonds'),
(5, 'Ten', 'Diamonds'),
(6, 'King', 'Diamonds')]
It works because the original Suits
list was changed from ["Hearts","Diamonds"] to["Hearts"]*3 +["Diamonds"]*3.
This feels contrived; although it works, I'm looking for a better solution.