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 trialJeffrey Rosenthal
4,539 Pointsno zip function??
my code totally works in the compiler, and i dont want to rewrite it all ugly when that lovely zip function is just sitting there. I mean i will, but I figured I'd write this question, just cause my solution does produce the desired result.
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
# If you use .append(), you'll want to pass it a tuple of new values.
def combo(one, two):
return zip(one,two)
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsYou are very close. The zip
function returns a zip object
. To evaluate this object, wrap it in list()
:
>>> one = [1, 2, 3]
>>> two = 'abc'
>>> zip(one, two)
<zip object at 0x7f277bbb8288>
>>> list(zip(one, two))
[(1, 'a'), (2, 'b'), (3, 'c')]
def combo(one, two):
return list(zip(one,two))
Jeffrey Rosenthal
4,539 PointsJeffrey Rosenthal
4,539 PointsThanks! they seem to print exactly the same in the compiler, that really threw me off!