Thursday, February 9, 2012

Numbering Things with MapIndexed

Sometimes you just want to number a List or Parts of an Expression. For example, I often want to number things that I'm putting into TableForm. Here's a simple idiom using MapIndexed. MapIndexed puts the indices as the second Part of each Expression, which the Reverse clause reverses so the number appear as the first column in TableForm.


MapIndexed[List, $Path] // Reverse /@ # & // TableForm


No comments:

Post a Comment