The question is as follows:
"A string exists in CamelCase format. For example: "ThisIsACamelCaseString".
A procedure/function is required that will:
1) prompt for the original entry
2) separate each word of the string
3) store each word in a separate array/list element
4) fill unused array/list elements with a rogue string such as "(Empty)".
After processing the preceding example, the array contents will look like this:
This
Is
A
Camel
Case
String
(Empty)
(Empty)
(Empty)
(Empty)
You may assume that the original string will contain no more than 10 separate words. Write program code in Python for this design."
This is what I tried:
a = input("Enter: ")
lists = list(a)
len = len(a)
alpha = ["Empty"]*10
alpha[0] = lists[0]
for i in range(len):
for j in range(len):
if lists[j + 1].isupper():
break
alpha[i] = alpha[i] + lists[j + 1]
for i in range(10):
print(alpha[i])
How do I find suitable code?
This is one way to do it:
a = 'ThisIsACamelCaseString'
b = [i for i, e in enumerate(a) if e.isupper()] + [len(a)]
c = [a[x: y] for x, y in zip(b, b[1:])]
final = ['(Empty)']*10
for i, case in enumerate(c):
final[i] = case