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 trialjohn larson
16,594 PointsCreate a function named combo that takes two iterables.
I already passed the challenge so I started exploring. This code is a bit lengthier than necessary. I just wanted to see if I could do it with slices.
def combo(iter1, iter2):
tup_list = []
combo_list = [None] * (len(iter1)+len(iter2))
combo_list[::2] = iter1
combo_list[1::2] = iter2
index1 = 0
index2 =index1+1
for item in combo_list:
#
try:
tup_list.append((combo_list[index1], combo_list[index2]))
index1 +=2
index2 +=2
except IndexError:
break
return tup_list
Remarkably, this one also passed the challenge.
1 Answer
Steven Parker
231,269 PointsMost challenges will accept any method that produces the correct result.
Although they are certainly intended to give you opportunities to practice the techniques introduced in the videos just prior to the challenge.
But there are some exceptions, for example, until recently you could pass this particular challenge with this compact solution (but it is no longer accepted!):
def combo(iter1, iter2):
return list(zip(iter1, iter2))
john larson
16,594 Pointsjohn larson
16,594 PointsThanks Steve.