I have seen solutions to this problem is other problems, but not in Python. I was wondering, how do I insert a character in a string after every x amount characters? For example, a forward-slash after every fourth character:
Before:
AsQs7d4dJh2h
After:
AsQs/7d4d/Jh2h
I know in Python I would have to use slice notation.
x = AsQs7d4dJh2h
x = x[0:4]
but this only gives me the first instance, I would like to be able to do this on any string regardless of the length of that string
UPDATE NEW PROBLEM:
What I am trying to do is separate the string in to card pairs, (2-card texas holdem), the problem is that the algorithm doesn't take into account the '10' card so separating into every 4 doesn't work, for instance this happens when faced with a 10 card in the string:
AsQs/10dA/h10h/2h
AsQs/10dA/h9h8/h
AsQs/10dA/h9h7/h
AsQs/10dA/h9h6/h
AsQs/10dA/h9h5/h
AsQs/10dA/h9h4/h
AsQs/10dA/h9h3/h
AsQs/10dA/h9h2/h
AsQs/10dA/h8h7/h
AsQs/10dA/h8h6/h
So what I need help with is how do I insert a forward slash or extract all the 2 card hands (in this instance 3 hands) from the string regardless if it has 1 or multiple '10' cards in the string?
Complete algorithm:
import itertools
strOutput = ""
lstMaster = ['As', 'Ks', 'Qs', 'Js', '10s', '9s', '8s', '7s', '6s', '5s', '4s', '3s', '2s',\
'Ad', 'Kd', 'Qd', 'Jd', '10d', '9d', '8d', '7d', '6d', '5d', '4d', '3d', '2d',\
'Ac', 'Kc', 'Qc', 'Jc', '10c', '9c', '8c', '7c', '6c', '5c', '4c', '3c', '2c',\
'Ah', 'Kh', 'Qh', 'Jh', '10h', '9h', '8h', '7h', '6h', '5h', '4h', '3h', '2h']
tupMasterEdited = itertools.combinations(lstMaster, 6)
lstMasterEdited = list(tupMasterEdited)
for combo in lstMasterEdited:
combo = str(combo).replace("(", "").replace(")", "").replace(" ", "").replace(",", "").replace("'", "")
combo = '/'.join([combo[i:i+4] for i in range(0, len(combo), 4)])
print(combo)