split.py 803 Bytes
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
# Author: Brice Colombier
# Laboratoire Hubert Curien
# 42000 Saint-Etienne - France
# Contact: b.colombier@univ-st-etienne.fr
# Project: CASCADE
# File: split.py
# Date : 2016-10-12


def split(m, size):
"""Split a list into blocks of equal size

>>> split([0, 1, 0, 1], 2)
[[0, 1], [0, 1]]
>>> split([0, 1, 0, 1, 0, 1, 0, 1], 4)
[[0, 1, 0, 1], [0, 1, 0, 1]]
"""

m_ret = m
for i in range(int(len(m)/size)):
m_ret.append([m_ret.pop(0) for w in range(int(size))])
return m_ret

if __name__ == "__main__":
message_Alice = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]
message_Bob = [0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0]
size = 8
split(message_Alice, size)
print(message_Alice)
print(message_Bob)