Python Gem #9: itertools.chain

Adam Short
Sep 4, 2017 · 1 min read
intermed = [sum(x) for x in lsofls]
result = sum(intermed)
chain([1,2,3], [4,5,6]) # ==> itertools.chain object of [1, 2, 3, 4, 5, 6]
chain(*lsofls) # ==> itertools.chain object of [1, 2, 3, 4, 5, 6]
result = sum(chain(*lsofls))

Adam Short

Written by

full stack engineer 🐺 18. works @ Stella AI

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade