blob: ca4df0cc2deee5f0236c4d3e491491e72732b6bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
## Example 1
## strInput = "ABC-D-E-F"
## nInput = 3
## Example 2
## strInput = "A-BC-D-E"
## nInput = 2
## Example 3
strInput = "-A-B-CD-E"
nInput = 4
arrSplit = strInput.split("-")
arrOutput = []
strTemp = arrSplit[-1]
for strLoop in arrSplit[:-1][::-1]:
if len(strTemp) == nInput:
arrOutput.insert(0, strTemp)
strTemp = strLoop
else:
strTemp = strLoop + strTemp
arrOutput.insert(0, strTemp)
print ("-".join(arrOutput))
|