I have been given, by someone else, a line of code that I am having trouble understanding.
inputString = "[1,2,3,4,5,6,7,8,9,10,11,12]"
a = inputString[1:-1].split(',')
z = zip(a[::2],a[1::2]) # this line
print a
print z
I understand the split
function and how that is operating. I even understand the zip
function. What I don't understand is what a[::2],a(1::2)
is doing. I have tried modifying these bits of code and get varying results, but nothing that allows me to comprehend what modifying the code does. I am fairly new at Python, and could use a little help.
Typical, unmodified result from the code looks like this:
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
[('1', '2'), ('3', '4'), ('5', '6'), ('7', '8'), ('9', '10'), ('11', '12')]
I am trying to get the result of 'a' to split into groups of 4 instead of groups of two, ie:
('1','2','3','4'),('5','6','7','8')....etc.