Turn flat list into two-tuples

python

Solution

This is quite short:

zip(input, input[1:])[::2]

Problem

Is there a single line expression to accomplish the following: ``` input = ['this', 'is', 'a', 'list'] output = [('this', 'is'), ('a', 'list')] ``` My initial idea was to create two lists and then zip them up. That would take three lines. The list will have an even number of elements.

Original source

Related problems