I am having some trouble reaching my goal of reducing coupons for betting in python.
I am trying to reduced rows of bets in 1X2-form to combined coupons. Since the rows are generated by another software they come as single rows and not combined ie. 8 games on one row = 1X21X21X, 1XX1X21X, 1X11X21X etc.
Better look at 3 rows:
1 1 1
X X X
2 X 1 <-- diff
1 1 1
X X X
2 2 2
1 1 1
X X X
The diff could of course be anywhere and there could be diffs in all positions.
Now I want to read every row and then combine as many rows as possible to something like this: 1,X,1X2,1,X,2,1,X (example for the three rows above)
Better look:
1
X
1X2
1
X
2
1
X
I have tried to get this result by looping through the rows and matching them one by one to the same rows. But to no avail.
Last effort has resulted in a nested dict like this:
{u'1': {u'X': {u'1': {u'1': {u'X': {u'2': {u'1': {u'X': ''}}}}},
u'X': {u'1': {u'X': {u'2': {u'1': {u'X': ''}}}}},
u'2': {u'1': {u'X': {u'2': {u'1': {u'X': ''}}}}}}}}
But from there I have no good idea of how to do. And is this a good way to go?
I am very thankful for any help in this matter, preferably with some code examples. Thanks!
Update, thanks to Aaron Hall:
My 20 rows:
product_list = '''2222XX12
22X2XX12
2212XX12
221XX212
221XX112
222XX212
222XX112
22XXX212
22XXX112
22X2X212
22X2X112
2X1XX212
2X1XX112
2X12X212
2X12XX12
2X12X112
2XX2X212
2XX2XX12
2XX2X112
2XXXX212
'''
Making the betting slip:
product_list = product_list.splitlines()
betting_slip = [set(i) for i in zip(*product_list)]
We get one betting slip:
pprint(betting_slip)
[set([u'2']),
set([u'2', u'X']),
set([u'1', u'2', u'X']),
set([u'2', u'X']),
set([u'2']),
set([u'1', u'2', u'X']),
set([u'1']),
set([u'2']),
Making that betting slip back to single rows:
txt_sets = [set(line) for line in betting_slip]
product_list = list(itertools.product(*txt_sets))
product_list = [''.join(tuple_i) for tuple_i in product_list]
And that results in 36 rows:
pprint(product_list)
[u'2X1XX112',
u'2X1XXX12',
u'2X1XX212'
...
Problem
But that's the problem I have right now. The betting slip we created now holds 36 rows or combinations. What I want is betting slip/slips that only holds those 20 rows that we started with.
I made a picture illustrating the betting slips: https://i.stack.imgur.com/5tEEn.png
As you can see the 20 rows should result in 6 betting slips and not one that holds 36 rows.