Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • $\begingroup$ Thank you, it works! Can you explain me what #[[1,{2,3,4,5}]]&] does, please? $\endgroup$ Commented Aug 4, 2020 at 8:39
  • 2
    $\begingroup$ Sure. Part of the culture of Mathematica is to turn lots of stuff into punctuation characters. Stuff followed by & is a function, but we just use it and don't give it any name, look at the documentation reference.wolfram.com/language/ref/Function.html This function is going to have a single argument and that is indicated by # which will be any one of the items in your list. Then #[[1]] will extract the first part of your rule. And #[[1,{2,3,4,5}]] is going to extract the 2nd through 5th items out of that first part. SortBy uses this to extract the items to sort by. Is that enough? $\endgroup$ Commented Aug 4, 2020 at 8:53
  • $\begingroup$ Perhaps compare this f[r_]:=r[[1,{2,3,4,5}]]; SortBy[listofrules,f] to the #& version and see if that helps you a little. You can also search the help system for things like [[ and that will provide some explanation on how this is extracting the desired bits. $\endgroup$ Commented Aug 4, 2020 at 17:08