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 trialDimitar Tsvetkov
6,806 PointsFunction combo() challenge
Hi guys, please help me get it right. What is wrong with my code? Thank you!
# 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
#iterable1 = [1, 2, 3]
#iterable2 = 'abc'
iterable1 = [1, 2, 3]
iterable2 = 'abc'
def combo(iterable1, iterable2):
for number in enumerate(iterable1):
for letter in iterable2:
print('{}: {}'.format(number, letter))
3 Answers
Gunhoo Yoon
5,027 PointsYou are just printing but question requires you to return them as value. Also, you are using enumerate kind of wrong.
Since enumerate knows about index and actual item you can use it to one of iterable to keep track on corresponding item on other iterable.
def combo(iterable1, iterable2):
result = []
for index, number in enumerate(iterable1):
result.append( (number, iterable2[index]) ) # Notice I'm passing tuple
return result
Dimitar Tsvetkov
6,806 PointsThank you! I see now what I was missing!
Andrew Voitsekhovskyy
3,523 PointsWhy it didn't work using zip function?