I want to iterate it through the Python (3.8.5) list and append two items at a time into a list of lists. The source list will always contain an even number of an element.
example output:
[['a','b'],['c','d']['e','f'],['g','h']]
I have tried range function, for loop, while loop, etc. I am seeking an eloquent, efficient way to do it. Below are the two incorrect pathways I have explored using the example data.
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']
letter_pairs = []
count = 0
for i in range(2):
for letter in letters:
letter_pairs.append([letter, letter])
while count < 2:
for letter in letters:
letter_pairs.append([letter, letter])
count += 1