Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(4)  |  Call(3)  |  Derive(0)  |  Import(1)
Takes a list and splits it into tuples of size n.

        def tuplify(l, n=2):
	"""
	Takes a list and splits it into tuples of size n.
	""" 
	return [tuple(l[i:i+n:]) for i in range(0, len(l), n)]
        


src/l/i/list115utils-1.0.1/list115utils/test/test_listutils.py   list115utils(Download)
        self.assertDictEqual(subdict(self.test_dict, 'gut'), {})
 
from list115utils import tuplify
class TestTuplify(TestListUtils):
    def setUp(self):
        self.test_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
 
    def test_tuplify_returns_proper_2_tuples(self):
        self.assertSequenceEqual(tuplify(self.test_list), [('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h'), ('i', 'j')])
    def test_tuplify_returns_proper_3_tuples(self):
        self.assertSequenceEqual(tuplify(self.test_list, n=3), [('a', 'b', 'c'), ('d', 'e', 'f'), ('g', 'h', 'i'), ('j', ), ])
 
    def test_tuplify_work_with_short_lists(self):
        self.assertSequenceEqual(tuplify([1,2,3], n=4), [(1,2,3), ])