We are working in a group of four and have spent the last few hours tring to debug/fix our code to get the right output. Below you will find our code the list in which the string is in and required output. Please help.
Our code is:
def reverse(my_list, number):
string = ""
new_list = []
count = 0
if number > len(my_list):
number = len(my_list)
if number < 2:
for k in my_list:
new_list.append(k)
return my_list
for index in range(number-1,-1,-1):
new_list.append(my_list[index])
for index in range (number, len(my_list)):
new_list.append(my_list[index])
return new_list
list in which string is in:
print("\nreverse Test")
str_list6 = ['e', 'd', 'u', 'd']
str_list7 = ['m', 'o', 'b', 'b', 'e', 'd']
new_list = list_function.reverse(str_list6, 4)
print(new_list)
new_list = list_function.reverse(str_list7, 3)
print(new_list)
new_list = list_function.reverse(str_list6)
print(new_list)
Required output is:
reverse Test
['d', 'u', 'd', 'e']
['b', 'o', 'm', 'b', 'e', 'd']
['d', 'u', 'd', 'e']
What I have tried:
We are working in a group of four and have spent the last few hours tring to debug/fix our code to get the right output. Below you will find our code the list in which the string is in and required output. Please help.