Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Lists Combining Lists

Ritul Sharma
Ritul Sharma
2,657 Points

Using .extend(), .append(), or +, add two new items onto the end of best. Again, the items can be anything you want.

i am using best.append(4,5) but it says it looks like task 1 is no

lists.py
best=[1,2,3]
best.append[5,4]

6 Answers

Umesh Ravji
Umesh Ravji
42,386 Points

Hi there Ritul, you aren't using the append method correctly, hence your error :)

In order to add two new items you are going to have to call the append method twice:

best=[1,2,3]
best.append(5)
best.append(4)

Make sure you understand the difference between that, and the following, as it doesn't result in the best list containing 5 different numbers, but actually it contains [1, 2, 3, [5, 4]]

best=[1,2,3]
best.append([5, 4])

Why can't you append 2 list items at once to the list? Like why couldn't I do:

best.append(5,4)
Umesh Ravji
Umesh Ravji
42,386 Points

Since I just happen to be using PyCham for an assignment anyways..

best = [1, 2, 3]
best.append(5, 4)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: append() takes exactly one argument (2 given)

The append() method only takes one argument.

best=[1,2,3] best.append(5) best.append(4)

why do i need to do this twice why can't it just be on one line ?

Milan Liyanage
seal-mask
.a{fill-rule:evenodd;}techdegree
Milan Liyanage
Python Web Development Techdegree Student 2,921 Points

Hi guys, the question is "Using .extend(), .append(), or +, add two new items onto the end of best. Again, the items can be anything you want. "

So first of all we have to create that list with three items in it (task 1), and use extend first and you can choose a one between append() or +.

Here's my answer and it worked for the task number 2

best = [12, 12, 1998]
best.extend(["milan"])
best.append("programmer")

@Milan. I'm sure you also failed to understand the question my fellow coder. The correct answer should be as follows: best = ["hello","obest","duncan"] best.extend(["esther","sister"]) I am very new to coding but here we only need to add TWO items to the best list. This will actually make best have a total of 4 items not 5. Hence u can also choose either the .append(["esther","duncan"]) or do the same with +.

Milan Liyanage
seal-mask
.a{fill-rule:evenodd;}techdegree
Milan Liyanage
Python Web Development Techdegree Student 2,921 Points

Task 1

best = [12, 12, 1998]

Task 2

best = [12, 12, 1998]
best.extend(["milan"])
best.append("programmer")

Task 3

best = [12, 12, 1998]
best.extend(["milan"])
best.append("programmer")

best.insert(0, "start")

@Milan. if there was an AND between .extend()....and .append then in english your arguement was going to stand

Use extend to add to the list. best = ["song", "now", "fabulous"] my_best = ["love", "great"] best.extend(my_best)