Python – Chunked interleave of Lists
Sometimes, while working with Lists, we can have a problem to perform merge operation. The simpler version is easy to implement. But when it comes to implement a variation of it, i.e the case in which we need to interleave in chunks alternatively, it becomes a tougher task. Let’s discuss certain way in which this task can be performed.
Method : Using loop +
This task can be performed by using the above functionalities. In this, we compute the iterations required and then run a loop as many times. We add elements in list using extend() and variable number specified.
The original list 1 is : [4, 5, 6, 8, 10, 11] The original list 2 is : [6, 7, 8, 9, 8, 12] List after chunked merge : [4, 5, 6, 6, 7, 8, 8, 10, 11, 9, 8, 12]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course