I'm struggling with a question at the moment and was wondering if someone could point out and show me where I'm going wrong. I need to insert a string into a list only using the append method at a designated position specified by an insert_position. Here is my code:
str1_list = ['one', 'three', 'four']
def insert_value(my_list, value, insert_position):
new_list = []
for i in range(len(my_list)):
if i < insert_position:
new_list.append(my_list[i])
elif i == insert_position:
new_list.append(my_list[i])
else:
new_list.append(my_list[i-1])
return new_list
print(str1_list, 'two', 1)
Output should be:
['one', 'two', 'three', 'four']
I know the value parameter needs to be somewhere but can't figure out where. Any help will be greatly appreciated.
Thanks
.appendneed to be called onnew_list?.appendmethod ? Anything else is accepted ? no methods in view at all ?