>>> line = '1234567890' >>> n = 2 >>> [line[i:i+n] for i in range(0, len(line), n)] ['12', '34', '56', '78', '90']
Here is what the above code is Doing:
1. We have a string, line, and a number, n.
2. We create a list comprehension that loops over the string, line.
3. We use the range function to loop over the string, line, in steps of n.
4. We use the string slicing method to extract substrings of length n from the string, line.
5. We store the substrings in a list.
6. We print the list.