Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Combining Lists

Combine list_1 and list_2 into a new variable named list_3. You can combine lists the same way you combine strings.

hi. help please. how do i combine list_1 and list_2. whats wrong with code list_1 = [1, 2, 3] list_2 = ["Hello", 5, {}] list_3 = [1, 2, 3] + ["Hello", 5, {}]

lists.py
list_1 = [1, 2, 3]
list_2 = ["Hello", 5, {}]
list_3 = [1, 2, 3] + ["Hello", 5, {}]

2 Answers

Hie. You combine the two lists using (+), just like the way you do it when combining strings:

list_1 = [1, 2, 3]

list_2 = ["Hello", 5, {}]

  #now, combine both lists
list_3 = list_1 + list_2 
Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You're right, that should pass. Dicts are, unfortunately, unhashable so how I was testing it was throwing an uncaught exception. I've updated it and your code should pass just fine now.

Thanks for finding this!