FAQ: Code Challenge: Lists - Append Size

This community-built FAQ covers the “Append Size” exercise from the lesson “Code Challenge: Lists”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Append Size

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I tried this :

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

it returns NONE


1 Like

Because the list.append() method does not have a return value. We need to return the list after appending to it.

return lst

Thank you Roy for your answers. Just after my post I found the solution. So I could finish this path and it’s because of your help. It was challenging at the beginning but oh so rewarding at the end :slight_smile:
How long have you been programming and with which language did you start?

1 Like

Before joining CC I developed old-school webs for some local non-profits, learning as I went. HTML/CSS were my first languages, then a few years in I started to learn JS, followed up by PHP. I didn’t really get into learning in depth until I joined here. I learned Python and Ruby here, but have kept my focus on beginner and intermediate level problem solving, hence you see me here on the front line with the newbies.


Great experience ! Thank you for being with us, Roy :slight_smile: (the newbies)

1 Like

I had used print(sorted_list) instead of return sorted_list. Output showed the sorted list followed by NON. Can someone explain why I get NONE with the Print statement?
#Write your function here
def combine_sort(lst1, lst2):
unsorted = lst1 + lst2
sortedList = sorted(unsorted)
print (sortedList)

#Uncomment the line below when your function is done
print(combine_sort([4, 10, 2, 5], [-10, 2, 5, 10]))

Returns None and the print outputs it as such.

Replace the print (sortedList) with return sortedList and let the print statement at the end handle the output. That way it will have a return value to print.

I don’t know why I get None for this code. Can anyone help?
def append_size (lst):
x = len(lst)
new_list = lst.append(x)
return new_list

The append method has no return so new_list will be None. Instead, append directly to lst and do not assign it. The expression is for all intents, a statement.

return lst

I got it. Thank of helping!

1 Like

Thanks for everyone’s help above, I also got it! I made mine a bit simpler though:

def append_size(lst):
  return lst
1 Like

it is simpler, thanks!