Python Forum
List modification returns none
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List modification returns none
#1
Here's the end of a short program I wrote:

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
Reply


Messages In This Thread
List modification returns none - by Mark17 - Aug-30-2019, 02:59 PM
RE: List modification returns none - by Yoriz - Aug-30-2019, 03:15 PM
RE: List modification returns none - by Mark17 - Aug-30-2019, 03:45 PM
RE: List modification returns none - by jefsummers - Aug-30-2019, 04:09 PM
RE: List modification returns none - by Yoriz - Aug-30-2019, 04:10 PM
RE: List modification returns none - by Mark17 - Aug-30-2019, 07:16 PM
RE: List modification returns none - by Mark17 - Sep-02-2019, 05:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Filer and sort files by modification time in a directory tester_V 5 337 May-02-2024, 05:39 PM
Last Post: tester_V
  function returns dataframe as list harum 2 1,459 Aug-13-2022, 08:27 PM
Last Post: rob101
  function that returns a list of dictionaries nostradamus64 2 1,792 May-06-2021, 09:58 PM
Last Post: nostradamus64
  Scaled scatter modification yvrob 1 1,996 Nov-08-2019, 04:05 AM
Last Post: yvrob
  Python script modification rajannn 1 1,946 Oct-06-2019, 07:55 PM
Last Post: micseydel
  Inspect.getmembers with isclass returns an empty list Aldar 1 2,814 Oct-02-2019, 01:48 PM
Last Post: Aldar
  returns index of list if contains a word zarize 0 1,853 Sep-09-2019, 09:29 AM
Last Post: zarize
  Code modification okrus 0 1,839 Jun-24-2019, 01:23 PM
Last Post: okrus
  pyPDF2 nautilus columns modification AJBek 1 2,941 Jun-07-2019, 04:17 PM
Last Post: micseydel
  Access the full list using an api that rather returns only a few elements bharath 1 2,598 Mar-08-2018, 02:55 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020