Aug-30-2019, 02:59 PM
Here's the end of a short program I wrote:
Middle is supposed to return the original list without the first and last items.
Program output is as follows:
Enter value for list. If done, enter "done": a
Enter value for list. If done, enter "done": e
Enter value for list. If done, enter "done": i
Enter value for list. If done, enter "done": o
Enter value for list. If done, enter "done": u
Enter value for list. If done, enter "done": done
Created list is ['a', 'e', 'i', 'o', 'u'] .
The list has 5 members.
New list generated by chop function is None
New list generated by middle function is None
I have two questions:
1. Why _does_ chop return None?
2. Why _doesn't_ middle simply remove first and last items of the list?
Thanks!
Mark
targetm = [] def chop(lst): tgti = len(lst) - 1 #this is the last item index in the list del lst[tgti] #delete the last item del lst[0] #delete the first item def middle(targetm): targetm = target[1:len(target)-1] choplist = chop(targetc) #targetc is a copy of list "target", which was created earlier by user input middlelist = middle(targetm) print('New list generated by chop function is',choplist) print('New list generated by middle function is',middlelist)Chop is supposed to delete the first and last items in a list and return None.
Middle is supposed to return the original list without the first and last items.
Program output is as follows:
Enter value for list. If done, enter "done": a
Enter value for list. If done, enter "done": e
Enter value for list. If done, enter "done": i
Enter value for list. If done, enter "done": o
Enter value for list. If done, enter "done": u
Enter value for list. If done, enter "done": done
Created list is ['a', 'e', 'i', 'o', 'u'] .
The list has 5 members.
New list generated by chop function is None
New list generated by middle function is None
I have two questions:
1. Why _does_ chop return None?
2. Why _doesn't_ middle simply remove first and last items of the list?
Thanks!
Mark