[Solved] How do I make a function in python which takes a list of integers as an input and outputs smaller lists with only two values?


If you only want groups of two (as opposed to groups of n), then you can hardcode n=2 and use a list comprehension to return a list of lists. This will also create a group of one at the end of the list if the length of the list is odd:

some_list = ['a','b','c','d','e']
[some_list[i:i+2] for i in range(0, len(some_list), 2)] 

This will return:

[['a', 'b'], ['c', 'd'], ['e']]

2

solved How do I make a function in python which takes a list of integers as an input and outputs smaller lists with only two values?