Why doesn't this function append to a list?

I’m trying to figure out where I went wrong with this exercise:

https://www.codecademy.com/courses/learn-python-3/articles/python-code-challenges-lists

The idea is that they want a function that will take the length of a list, and then append that number to the end of the list.

So if the list is [23, 42, 108], the list is 3 items long and so the function would append ‘3’ and you would end up with [23, 42, 108, 3].

The listed solution is:

def append_size(lst):
  lst.append(len(lst))
  return lst

print(append_size([23, 42, 108]))

My attempted solution was:

def append_size(lst):
  size = len(lst)
  lst.append(size)
  
print(append_size([23, 42, 108]))

This returns a value of ‘None,’ and I’m not sure why. The function seems like it should be grabbing the length of the list (3) and saving it to the variable (size). Then - as I understand it - it should be appending ‘size’ (which is 3) to the end of the list. I highly suspect that the problem is that I’m not using ‘return,’ but I’m not sure. Thoughts?

yes, the problem is the missing return.
You probably need to return the list or its length so that it does what you want.

alternatively,
you can try having the list as a variable

def append_size(lst):
  size = len(lst)
  lst.append(size)

my_list = [23, 42, 108]
append_size(my_list)
print(my_list)

Ok very interesting, thanks!