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 trialhello lion
942 PointsCreate a function named combo() that takes two iterables and returns a list of tuples. Each tuple should hold the first
I get the right result :[(1, 'a'), (2, 'b'), (3, 'c')] , but still say me wrong, that is the several times, I think they have bug in here. that is my code:
ist1 = [1,2,3]
string1 = 'abc'
def combo(list1,string1):
list_empty = []
for i in range(3):
tuple1 = list1[i],string1[i] # put each item in list1 and string1 into the tuple1
list_empty.append(tuple1) # let each tuple1 save into the list_empty
return list_empty
print(combo(list1,string1))
[MOD: added ```python formatting -cf]
2 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsYour answer is very close. You are limiting the length of the iterables to three but you need to create a general solution. Adjusting the length of your range
to be based on the input should work.
ist1 = [1,2,3]
string1 = 'abc'
def combo(list1,string1):
list_empty = []
for i in range(len(list1)):
tuple1 = list1[i],string1[i] # put each item in list1 and string1 into the tuple1
list_empty.append(tuple1) # let each tuple1 save into the list_empty
return list_empty
print(combo(list1,string1))
hello lion
942 Pointsthank you telling me. Merry Christmas.