I am having difficulty converting a camel case string into separate words and appending these into a list. It almost completes the code but it gives an IndexError: string index out of range. Please could anyone help with this?? The output when run is:
['This']
['This', 'Is']
['This', 'Is', 'A']
['This', 'Is', 'A', 'Camel']
['This', 'Is', 'A', 'Camel', 'Case']
Traceback (most recent call last):
for i in string[char]:
IndexError: string index out of range
List = []
string = "ThisIsACamelCaseString"
newstring = ""
count = 0
char = 0
null = 0
for i in string[char:]:
if i == i.upper():
newstring = newstring + i
count += 1
char += 1
for i in string[char]: **< error here**
if i == i.upper() and char == 1:
null += 1
elif i == i.lower():
newstring = newstring + i
char += 1
count += 1
elif i == i.upper() and count > 0:
List.append(newstring)
print(List)
newstring = ""
break