Multiple Tuple to Two-Pair Tuple in Python?

data-structures, python, tuples

Solution

`zip()` is your friend:

t = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
zip(t[::2], t[1::2])

Problem

What is the nicest way of splitting this: ``` tuple = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h') ``` into this: ``` tuples = [('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')] ``` Assuming that the input always has an even number of values.

Original source