Created
November 16, 2022 14:30
-
-
Save cfjedimaster/4b57bb47d523c2e52c5179e187a375cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def combineString(input, size): | |
result = [] | |
marker = 0 | |
tempStr = "" | |
while(marker < len(input)): | |
if(tempStr == ""): | |
tempStr = tempStr + input[marker] | |
else: | |
tempStr = tempStr + " " + input[marker] | |
if marker < len(input)-1: | |
nextSize = 1 + len(input[marker+1]) | |
else: | |
nextSize = 0 | |
if (len(tempStr) + nextSize) > size: | |
result.append(tempStr) | |
tempStr = "" | |
elif marker == len(input)-1: | |
result.append(tempStr) | |
marker = marker + 1 | |
return result | |
input1 = ["a","b","c","d","e","f","g"] | |
print(combineString(input1, 5)) | |
print(combineString(input1, 12)) | |
input2 = ["alpha", "beta", "gamma", "delta", "epsilon"] | |
print(combineString(input2, 20)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment