# Confused about how Partition works

I have a problem about the padding list about Partition command. For instance,

Partition[{a, b, c, d, e, f, g}, 3, 1, {-2, 1}, {x, y, z}]

{{z, a, b}, {a, b, c}, {b, c, d}, {c, d, e}, {d, e, f}, {e, f, g}, {f,g, y}, {g, y, z}}


However, my understanding about padding list shown as below:

Another example

Partition[{a, b, c, d, e, f}, 3, 3, {1, 1}]

 {{a, b, c}, {d, e, f}}


My understanding:

### Question

Can someone give me a good explanation?

• I tend to agree with you about what the expected output should be. I don't have an explanation unfortunately but look forward to reading one if someone can explain it. Jan 29, 2015 at 6:39
• Related: (64925) (your own question) Jan 29, 2015 at 7:35
• I just want to add I really like the way you ask your questions!
– Kuba
Jan 29, 2015 at 12:52
• @Kuba,Thanks, I am very happy to hear that:) I found gradually that the understanding of construct is very important for learnnig Mathematica.
– xyz
Jan 29, 2015 at 13:03

### Example #1

Let me make your example a bit smaller for brevity:

Partition[{a, b, c, d}, 3, 1, {-2, 1}, {x, y, z}]

{{z, a, b}, {a, b, c}, {b, c, d}, {c, d, y}, {d, y, z}}


This is in effect:

PadRight[{a, b, c, d}, 7, {x, y, z}, 1]

Partition[%, 3, 1]

{z, a, b, c, d, y, z}

{{z, a, b}, {a, b, c}, {b, c, d}, {c, d, y}, {d, y, z}}


+
Equals

### Example #2

The documentation states:

Critical to your example is: "appear at or after position kR in the last sublist."

Therefore in this case it does not matter if kR is any of: 1, 2, 3, -1, -2, -3, because each will be satisfied by:

{{a, b, c}, {d, e, f}}


Partition does not violate the cyclic order of the list. For the output to be as you anticipated:

{{a, b, c}, {d, e, f}, {f, a, b}}


The element f would have to be taken out of sequence; the next element should be a.

• +1, Good explanation, thanks:), Could you give me a explanation about another example,See update of my question.
– xyz
Jan 29, 2015 at 7:08
• Ok,@Mr.Wizard, Today, I found that the understanding of the advanced usage of Partition is the basis of understanding the built-in function(like ListCorrelate, ListConvolve etc).
– xyz
Jan 29, 2015 at 7:17
• thanks. thinking in terms of how PadRight works explains it. Jan 29, 2015 at 7:25
• @ShutaoTang Please see my update and tell me if it is understandable. Jan 29, 2015 at 7:33
• OK,@Mr.Wizard, I got it:)
– xyz
Jan 29, 2015 at 11:54