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) 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,868 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.