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!
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
why is this is wrong?
it seems to be working in the console, all names do move to the Beatles [list], but when this method is used to answer the question the program is expecting ".extend" and it was flagged as wrong.
are both method ok to use in a real-world scenario or besides that it works this would be considered bad practice or something like that?
beatles = ["John"] others = ["George", "Ringo"] beatles.append("Paul") beatles.append([others])
Eric M11,543 Points
This is not an academic distinction purely for practicing extend, are you sure your console is showing exactly what is requested?
list.extend() actually do different things when passed another list as arguments.
The code that you've provided will lead the list
beatles to contain
['John', 'Paul', ['George', 'Ringo']]
This is not a 4 item list containing strings. This is a 3 item list (try
len(beatles)) containing two strings and a list. Index 0 is "John", index 1 is "Paul", index 2 is a list containing 2 items.
Append adds to the end of the list. Extend will add items from one list to another.
Barry Snowe51,277 Points
It seems that the interpreter expects something other than .append() to add the array. .append() worked fine for one value. Maybe try .extend() and see what happens.