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 (2016, retired 2019) Tuples Combo

Ong Jia Rui
Ong Jia Rui
1,731 Points

Using zip()

I tried using zip() function to return results for this challenge, but I don't understand why the output is incorrect.

# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo(x, y):
    return zip(x, y)

2 Answers

William Li
William Li
Courses Plus Student 26,867 Points

I think it's pretty clear on the Bummer! message you received from using zip() to solve this problem. The instructor wants you to get some practices on the materials covered in the previous lectures, which means solving this code challenge by applying the Python knowledge we've learned so far in the course.

I agree that list(zip(x,y)) is a shortcut to solving this problem, but the whole idea of this code challenge is that you're supposed to write a simplified version of zip() in your own code; and making use of the zip() written by someone else defeats the purpose of practicing.

Ong Jia Rui
Ong Jia Rui
1,731 Points

Okay, I have seen list(zip(x,y)) work. But from my console, I see that zip() itself returns a list, so why can't it pass?

zip() returns an iterable. You have to explicitly convert it to a list if that's what you need.