Scrolling text. Rearrange the character. Characters in a string from index zero to last. I want to get the following result
Question:
def scrolling_text(string: str) -> list:
new_list = []
string = string.upper()
for i in range(0, len(string)):
string = string[i:] + string[:i]
new_list.append(string)
return new_list
print(scrolling_text('robot')) # ["ROBOT", "OBOTR", "BOTRO", "OTROB", "TROBO"]
Answers:
What you want to do to get the list is shift
the first letter of the string and append
it to the back of the remaining sub-string through slicing
:
def scrolling_text(string: str) -> list:
new_list = []
string = string.upper()
for i in range(0, len(string)):
if i != 0:
string = string[1:] + string[:1]
new_list.append(string)
return new_list
print(scrolling_text('robot')) # ["ROBOT", "OBOTR", "BOTRO", "OTROB", "TROBO"]
def scrolling_text(string: str) -> list:
new_list = []
string = string.upper()
for i in range(0, len(string)):
string = string[i:] + string[:i]
new_list.append(string)
return new_list
print(scrolling_text('robot')) # ["ROBOT", "OBOTR", "BOTRO", "OTROB", "TROBO"]
What you want to do to get the list is shift
the first letter of the string and append
it to the back of the remaining sub-string through slicing
:
def scrolling_text(string: str) -> list:
new_list = []
string = string.upper()
for i in range(0, len(string)):
if i != 0:
string = string[1:] + string[:1]
new_list.append(string)
return new_list
print(scrolling_text('robot')) # ["ROBOT", "OBOTR", "BOTRO", "OTROB", "TROBO"]