I was trying to do a codewar quiz, which needs to take in a string of text, and break up the camel case, and separate them into a list of words, I was expecting the result to be
['break', 'Camel', 'Case', 'Ez']
but I can't figure out which part of my code is causing problem
word_list = []
def solution(s):
global word_list
if any([char.isupper() for char in s][1:]):
# print([char.isupper() for char in s][1:])
for i, char in enumerate(s):
if i == 0:
continue
if char.isupper():
word_list.append(s[:i])
solution(s[i:])
else:
word_list.append(s)
return word_list
# print("breakCamelCaseEz")
print(solution("breakCamelCaseEz"))
the result I'm getting is
['break', 'Camel', 'Case', 'Ez', 'CamelCase', 'Ez', 'breakCamel', 'Case', 'Ez', 'breakCamelCase', 'Ez']
Also when I tried to add a counter to the function trying to find the problem, I get more problem
word_list = []
indexing = 0
def solution(s):
global word_list, indexing
indexing += 1
if any([char.isupper() for char in s][1:]):
print([char.isupper() for char in s][1:])
# break it down
for i, char in enumerate(s):
if i == 0:
continue
if char.isupper():
word_list.append(s[:i])
print("{}-{}".format("loop", indexing))
solution(s[i:])
else:
print("{}-{}-{}".format("else", indexing, s))
word_list.append(s)
return word_list
# print("breakCamelCaseEz")
print(solution("breakCamelCaseEz"))
I've read through the code for multiple times but still can't figure it out
*edited first part