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 trial
john larson
16,594 PointsI don't remember where I found this: but I think it's a clever way to combine lists and intersperse the values.
I guess I'm easily entertained :D
# 1: Goal
# intersperse and merge two lists
a = list("aceg")
b = list("bdfh")
# 2: create a space for each of the elements
c = [None]*(len(a)+len(b))
# 3: new list, c: = a, start at 0, every other space
c[::2] = a
# 4: now add the values from b to every other space
# starting at 1
c[1::2] = b
# 5: the new list
print(c)
#['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']