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
Mark Bekhet900 Points
the method that I should use.
Hi, I want to know what is the error that I am making in this objective. It says that the second list doesn't have two items and that the my_list should have a total of 6.
my_list = ["Mark" , "vegetables got him" , 3 , 5 , 6] my_list2 =["Kiro" ,True] my_list.extend(my_list2)
Grigorij Schleifer10,364 Points
Hi Mark, you do not need to create a second variable and then add it to the first list. Just declare ["Kiro" , True] inside of my_list
If you would like to add a new list on the end of a second list I would suggest using append() instead of extend(). Extend will take whatever is in the second list and add the items one after another.
>>> my_list = ["Mark" , "vegetables got him" , 3 , 5 , 6] >>> my_list ['Mark', 'vegetables got him', 3, 5, 6] >>> my_list2 =["Kiro" ,True] >>> my_list.append(my_list2) >>> my_list ['Mark', 'vegetables got him', 3, 5, 6, ['Kiro', True]] >>> my_list.extend(my_list2) >>> my_list ['Mark', 'vegetables got him', 3, 5, 6, 'Kiro', True] >>>
Append appends the entire list but extend extends does not.