Archive

Posts Tagged ‘equally’

split a string into equal length substrings

December 16, 2016 Leave a comment

Problem
Having a string, split it up to equally long substrings. Example: “110010110100” -> “11”, “00”, “10”, “11”, “01”, “00”.

Solution

>>> s = "110010110100"
>>> [s[i:i+2] for i in range(0, len(s), 2)]
['11', '00', '10', '11', '01', '00']

I found it here.

Categories: python Tags: ,