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 trialJesse Miller
7,920 PointsKeeps returning double
I've tried everything to return just one value from the lst. For example, I keep getting [(1,a), (1,b), (1,c), (2,a), (2,b), (2,c), (3,a), (3,b), (3,c)] instead what the criteria wants. Anyone know how to fix this?
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
# If you use .append(), you'll want to pass it a tuple of new values.
def combo(lst, string):
newlist=[]
for i in lst:
for k in string:
newlist.append((i, k))
return newlist
1 Answer
Steven Parker
231,275 PointsYou have two nested iterations, so you are paring each of the first items with every second list item.
What you want is a single iteration that will pair the first with the first, second with second, and so on.
Hint: use a counter to index both lists at the same time.
I'll bet you can do it now. But if you're still stuck (don't look below until you try!):
SPOILER ALERT
def combo(lst, string):
newlist=[]
for i in range(len(lst)):
newlist.append((lst[i], string[i]))
return newlist