Python Forum
help returning a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help returning a list
#1
hey guys, I'm trying to write a small script to return a list of numbers that are input however for the life of me I cannot get it to work, below is the script that I have and that is also straight out of my text book, whenever I am putting numbers in it is just giving me the same thing that I entered I need it to tell me how many numbers are in the list, I know that this seems really basic but I'm just learning can anyone help and keep it as simple as possible or as close to the example below that is from my book - if any help im using IDLE 3.7.0 thanks and appologies to the mods if I have not put the code in properly below

def list_length(a_list):
    """"Return the length of a list."""
    length = 0
    for item in a_list:
        length = length + 1
    return length
Reply
#2
to get length of a list, it's simply len(listname) , to return a list from a function, return listname
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can anyone spot why this function is returning an empty list? hhydration 2 1,839 Nov-18-2020, 06:16 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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