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 trialArjun Amin
2,228 PointsCreate a function named combo() that takes two iterables and returns a list of tuples. Each tuple should hold the first
Hi Please can someone help me with this because I am not sure of inumerator works and am trying to solve the above problem
# combo(['swallow', 'snake', 'parrot'], 'abc')
# Output:
# [('swallow', 'a'), ('snake', 'b'), ('parrot', 'c')]
# If you use list.append(), you'll want to pass it a tuple of new values.
# Using enumerate() here can save you a variable or two.
def combo(it1,it2):
finalList = []
count = 0
for index in it1:
thing = (it1[count],it2[count])
finalList[count] = thing
count += 1
continue
return finalList
1 Answer
Anish Walawalkar
8,534 Pointsthis will solve your problem:
def combo(item1, item2):
x = []
for index, item in enumerate(item2):
x.append((item1[index], item))
return x
or you can even do this:
def combo(item1, item2):
return zip(item1, item2)
Hope this helps