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 trialDmitriy Ignatiev
Courses Plus Student 6,236 Pointscombo
I couldn't solve it without zip. Please help me to understand.
could you pls explain how it could be solved with clarification
Many thanks for your help.
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
def combo (a,b):
list_t = []
for i in a, b:
n = (a[i], b[i])
return list_t
2 Answers
taejooncho
Courses Plus Student 3,923 PointsHi there,
Here is my answer and I will try to walk through it.
def combo(x, y):
combo_list = []
num = 0
for values in x:
results = (x[num], y[num])
combo_list.append(results)
num += 1
return combo_list
This for loop is going to make result variable hold a tuple of x[num], y[num]. num is going to be the index of the iterable variable. Whatever inside of variable result is going to append that to list combo_list. At the end of the for loop, num variable is going to be added by 1.
So what is going to happen is that at first, combo_list is an empty list and num is 0. The for loop is going to make results variable hold a tuple of x[0], y[0]. Next, the for loop will append the variable result into the list of combo_list. Lastly, the loop will add 1 to the num variable.
Now combo_list holds a tuple (x[0], y[0]) and num is now 1. the for loop goes again... The for loop is going to make results variable hold a tuple of x[1], y[1]. Next, the for loop will append the variable result into the list of combo_list. Lastly, the loop will add 1 to the num variable.
Eventually, the num variable will be big enough that it is bigger than the length of iterable variable x or y and nothing will get appended to the combo_list.
I hope this explanation helps and not confusing to you.
Dmitriy Ignatiev
Courses Plus Student 6,236 PointsHi, taejooncho
Thank you very much for your explanation. Now it's clear for me.
Once again, thank you.