My function aims to take a string as input then output the same string printed the number of times equal to the count of non-empty characters in the string, with the next non-empty element in the next list capitalized. The final output should contain the new strings in a list.
Example:
Input: hello
Output: ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
Function:
def cap_wave(str):
str_split = len([x for x in list(str) if x.isalpha()])
len_list = [list(str) for i in range(1, str_split+1)]
result = []
for i in range(len(len_list)):
temp = []
for t in len_list[i]:
char_modified = t
if not char_modified:
continue
else:
temp.append(char_modified)
result.append(temp)
new_nested = [[a.upper() if i == 0 else a for i, a in enumerate(b)] for b in result]
nest_joins = [''.join(x) for x in new_nested]
return nest_joins
The above function would fulfill all requirements except for capitalizing the next, and only the next letter, in the next string, eg ["Hello", "Hello", "Hello", "Hello", "Hello"]
. My gut says to count using index slicing, but I'm unsure how to implement without hitting index range errors.