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 trialRoja kajoka
701 Pointscan i have idea about that quiz?
help me please
# combo([1, 2, 3], 'abc')
# Output:
# [(1, 'a'), (2, 'b'), (3, 'c')]
3 Answers
Kobi Michaeli
31,461 PointsHi Gavin, you are correct, my bad, here is a different one
Kobi Michaeli
31,461 PointsHi Gavin, in most cases length has no meaning (unless you are doing some extra stuff in your code) here is a shorter way and even that can be written in a shorter way
def combo(l,r):
return [(l[i],r[i]) for i in range(0,len(l))]
but it is better to understand your code/or others code than to make it shorter and not so "readable"
Gav Cooper
4,261 PointsI like that version :) very succinct!
Oh I know there was no need to define length as its own variable, just in my head it felt a bit messy to write range(len(first)). It's probably just a quirk of mine more than anything!
Kobi Michaeli
31,461 Pointshere is an example:
def combo(l,r):
merged = []
for i in range(0,len(l)):
merged.append((l[i],r[i]))
return merged
Gav Cooper
4,261 PointsIf you use the zip function it doesn't count is as correct (I know this because I've just tried it!)
Gav Cooper
4,261 PointsGav Cooper
4,261 PointsThat's basically how I did it in the end (though your solution is a bit shorter than mine!)