Say I have a list with 9 elements I want to split that list after every third element
["a", 1, 2, "b", 1, 2, "c", 1, 2]
Output:
["a", 1, 2]
["b", 1, 2]
["c", 1, 2]
Any suggestions toward this?
Say I have a list with 9 elements I want to split that list after every third element
["a", 1, 2, "b", 1, 2, "c", 1, 2]
Output:
["a", 1, 2]
["b", 1, 2]
["c", 1, 2]
Any suggestions toward this?
Does this help with your question?
lst = ["a", 1, 2, "b", 1, 2, "c", 1, 2]
def chunks(lst, n):
for i in range(0, len(lst), n):
yield lst[i:i + n]
for i in chunks(lst, 3):
print(i)
RESULT:
['a', 1, 2]
['b', 1, 2]
['c', 1, 2]
CREDIT: How do you split a list into evenly sized chunks?
If you any other queries or doubts feel free to ask to me I'll be there!
Happy Coding!