From c3b35da638f5c2591314ebff538e610c963c994d Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Fri, 27 May 2016 19:11:36 +0100 Subject: [PATCH] added list chunking function to utils --- steam/util/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/steam/util/__init__.py b/steam/util/__init__.py index bf294d8..8444bf2 100644 --- a/steam/util/__init__.py +++ b/steam/util/__init__.py @@ -3,6 +3,12 @@ import weakref import struct import socket +import sys + +if sys.version_info < (3,): + _range = xrange +else: + _range = range def ip_from_int(ip): """Convert IP to :py:class:`int` @@ -53,6 +59,19 @@ def clear_proto_bit(emsg): """ return int(emsg) & ~protobuf_mask +def chunks(arr, size): + """Splits a list into chunks + + :param arr: list to split + :type arr: :class:`list` + :param size: number of elements in each chunk + :type size: :class:`int` + :return: generator object + :rtype: :class:`generator` + """ + for i in _range(0, len(arr), size): + yield arr[i:i+size] + class WeakRefKeyDict(object): """Pretends to be a dictionary.