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 trialDeniz Kahriman
8,538 PointsHow can I fix the code below? Trying to combine 2 iterables in tuples within a list. Thank you!
I was also thinking of using "enumerate" but not sure how to proceed. Thanks in advance!
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo(iterable1, iterable2):
my_list = []
for i in iterable1 and iterable2:
my_list.extend((iterable1[i], iterable2[i]))
return my_list
1 Answer
Steven Parker
231,236 PointsYou can't combine two iterables with "and" in a for loop.
But they did say you can assume both are the same length. Perhaps that might help you construct a loop.
Deniz Kahriman
8,538 PointsDeniz Kahriman
8,538 PointsHey Steven, I changed my approach but not sure if I'm in the right direction.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsIt looks like you have a good idea there, but you don't want your loop to run forever ("
while True
"). Instead of "True" use a conditional expression that will cause the loop to stop after it does all the items. Also, lists have a method for adding new items that might work better than assigning using an index.