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 trialreza sajadian
718 PointsZippy combo function doesn't work. Help me please.
I don't have a clear idea how shall my code work on this exercise.
# 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():
for item in enumerate(a):
for item in enumerate(b):
target = '{}: {},{}'.format(index, a, b)
return target
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsYou are on the right path. The end goal is a list of tuples. Also enumerate
generates two items each iteration: an index and a member of the container. So the for
loop must have two variables to receive them. You can use the index of the first loop to generate the second tuple item. The function needs two parameters for the two iterables passed in.
# [(1, 'a'), (2, 'b'), (3, 'c')]
# If you use .append(), you'll want to pass it a tuple of new values.
def combo(a, b):
# initialize target
target = []
for index, item in enumerate(a):
# append tuple to target
target.append((item, b[index]))
return target
Mike Tribe
3,827 Pointsdef combo(itr1, itr2):
tuplist = []
index = 0
for item in itr1:
tuplist.append((item, itr2[index]))
index += 1
return tuplist