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 trialAdam Raitano
5,387 PointsCreate a function named combo...
I'm getting the 'bummer' message here. It tells me that I'm effectively correct except for I have [(0, 'T'), (1, 'r'), (2, 'e')... and it's expecting [(1, 'T'), (2, 'r'), (3, 'e')...
What could I possibly be doing wrong here?
# 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(it1, it2):
silt = []
for item1, item2 in enumerate(it2):
new_silt = (item1, item2)
silt.append(new_silt)
return silt
2 Answers
Anish Walawalkar
8,534 PointsRemember that list indices always start at 0
# 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(it1, it2):
silt = []
for item1, item2 in enumerate(it2):
new_silt = (item1+1, item2)
silt.append(new_silt)
return silt
doing the following should fix your error
another way of doing this would be to use dic(zip(list1, list2)):
item1 = list(range(1, len(item2)+1)) # because you want to start at index 1
dictionary = dict(zip(item1, item2))
return dictionary
That should do it
Adam Raitano
5,387 PointsThanks for your response! I think I kind of misunderstood what I was supposed to do. I did, however, figure out the right way. Hooray!