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 trialBenjamin Bradshaw
3,208 PointsI'm Stumped
any pointers? am i just way off?
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo(arg1, arg2):
list1 = []
for abstract in range(len(arg1)):
double_tuple = list1.append(arg1[abstract], arg2[abstract])
return double_tuple
2 Answers
Ryan S
27,276 PointsHey Benjamin,
You are actually quite close. The only issue is the way you are appending items to double_tuple
.
The append()
method doesn't actually return a value, so on each iteration of your loop, nothing is getting assigned to double_tuple
. When all is said and done, it will have no value and will be of type "NoneType".
list1
, however, will have a value so you might as well just return it. And you can get rid of double_tuple
while you're at it since you won't need an intermediary variable.
Also, keep in mind that append()
can only take one argument so you will need to wrap your arguments in parentheses and pass in a single tuple, which is what the challenge is asking for.
def combo(arg1, arg2):
list1 = []
for abstract in range(len(arg1)):
list1.append((arg1[abstract], arg2[abstract]))
return list1
Hope this helps.
Benjamin Bradshaw
3,208 Pointsthat helps so much. thank you.
Clifford Gagliardo
Courses Plus Student 15,069 PointsAlso, I don't understand why you only need one iterating variable and not a second one to access the second argument.
Sorry for all the questions, but I am quite new to this and I only understand half of why this solution works.
seong lee
4,503 Pointsseong lee
4,503 Pointswow this explanation was the best explanation i have ever heard about this challenge. It also helped me to. thank you.
Clifford Gagliardo
Courses Plus Student 15,069 PointsClifford Gagliardo
Courses Plus Student 15,069 PointsI do not understand why the length of the first argument has to be found. How does this help solve the problem?