Python list take every nth element
Python Append List every Nth indexGiven 2 list, append list to the original list every nth index.
Method #1 : Using loop This is brute way to solve this problem, in this, every nth index, inner loop is used to append all other list elements. Python3
Output:
Method #2 : Using extend() Another way to solve this problem. In this, we use extend to get all the elements in every Nth index, rather than inner list. Python3
Output:
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
Article Tags :
Python
Python list-programs
Read Full Article
|