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 trialAlex Rendon
7,498 PointsI don't understand how I can do it. How do I put 'swallow' instead of 1... or I am thinking bad about the task?
Help me please.
1 Answer
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Alex
this is how i did it
# combo(['swallow', 'snake', 'parrot'], 'abc')
# Output:
# [('swallow', 'a'), ('snake', 'b'), ('parrot', 'c')]
# If you use list.append(), you'll want to pass it a tuple of new values.
# Using enumerate() here can save you a variable or two.
def combo(my_list,my_string):
output_list=[]
counter = 0
for letter in my_string:
output_list.append((my_list[counter],letter))
counter+=1
return output_list
print(combo(['swallow', 'snake', 'parrot'], 'abc'))
In my combo function line1 I -> declared a list of my own to hold the output tuple line 2 -> I created a counter that will help us access the values in the list passed to the function, note this will only work if the size of the list is the same as the length of the second argument my_string. line 3 -> i loop over the string to get each letter and append it to the second half of the tuple, note i did not loop over the list as i have this counter variable to access the values in it see line4. line5-> increment the counter by 1 each time it goes around the loop.
hope this helps.
Alex Rendon
7,498 PointsAlex Rendon
7,498 PointsAndreas, thanks so much!!!. I can understand now.