# Tag Info

Accepted

### How can I remove empty lists { } from a nested list?

Using ReplaceAll (which can also be written /.) we can replace all the empty lists { } with Nothing. ...
• 69.3k

### What's the difference between With and ReplaceAll?

With is a scoping construct, meaning that symbols localized by With will be unaffected by whatever value they may have outside ...
• 23.8k

### How to match a pattern only when it is not used as a head?

This trick is often useful with ReplaceAll: if you want some things to remain unaffected, you add a trivial replacement rule for that case before the replacement ...
• 23.8k
Accepted

### Why doesn't b = a; f[a_] := b; f[2] return 2?

Caution The post is long. If you just want to know how to fix the code, please search "fix the code in title in 10 ways" in the page. If you want to read discussions about global/local ...
• 67k

### Apply function to all first arguments of a nested list of rules

list = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h, 9 -> j}}}}; 1. MapAt ...
• 78.5k

### How can I remove empty lists { } from a nested list?

Using DeleteCases: ...
• 26.1k

### What's the difference between With and ReplaceAll?

The way With[{x=x0, …}, body] works is to take body, and replace every occurrence of x, etc. ...
• 67k
Accepted

### Why does this pattern not match?

The first one matches because HoldPattern just prevents the pattern from evaluation, so it is equivalent to ...
• 27.3k
Accepted

### How can I write Log[a]/Log[b] in the form Log[b,a]?

sol = First@ Solve[2^x + 2^{x + 4} + 2^{x + 3} == 3^x + 3^{x + 4} + 3^{x + 3}, x, Reals] // FullSimplify x /. sol /. Log[a_]/Log[b_] :> Defer[Log[b, a]] ...
• 55.7k
Accepted

### How to convert this logarithm into this form?

Using the property ...
• 146k
Accepted

### Create sublists whose totals exceed a certain threshold and that are as short as possible

Why not just use Most: ...
• 4,177

### Apply function to all first arguments of a nested list of rules

Using Replace / Map : ...
• 55.7k
Accepted

### Find non-descending sequences of list pairs

SequenceCases[list, x : {_, __} /; LessEqual @@ x[[All, -1]]]
• 30.3k
Accepted

### How to match a pattern only when it is not used as a head?

expr = -27 f + 27 f[1 + n] - 9 f[2 + n] + f[3 + n] == 1 + 3 n; p = Position[expr, f, Heads -> False] {{1, 1, 2}} ...
• 78.5k
Accepted

### Replace number in string with ? and /;

You've mixed up the usage of PatternTest (?) and Condition (...
• 67k
Accepted

### Reversing the order of function arguments by a replacement rule

expr = g[x3, x2, x1]; You must use RuleDelayed (:>) instead of Rule ...
• 78.5k
Accepted

### Plotting a function containing a $\pm$ sign

Define: ( because I can ) ...
• 55.7k
Accepted

### Replace a column/row of a matrix under a condition by a random number

Modify -> (Rule) to :> (RuleDelayed).
• 67k

### Why does Blank sometimes not match the empty expression?

One source of confusion here is about what MatchQ[, _] actually does. Contrary to what you think, the first argument of MatchQ here is not "the empty ...
• 23.8k

### How can I remove empty lists { } from a nested list?

list = {{{1}, {2}, {1, 2}, {1, 2, 3}, {}, {}}, {{2}, {3}, {}}}; p = Position[{}] @ list; {{1, 5}, {1, 6}, {2, 3}} ...
• 78.5k
Accepted

### Pattern matching based on parts of Head

Maybe something like this: Cases[expr, _?(StringMatchQ[ToString[Head[#]], "Fun*"] &), All]
• 30.3k
Accepted

### More concise forms generate list with elements 0 and 1

Update: An alternative approach to construct the restricted permutations directly (rather than filtering all permutations): ...
• 398k

### How to express the notion of "from "a" to the nearest "z"" with patterns?

str = "abczabvncz"; Borrowing the Shortest-pattern from vindobona (but with a triple underscore) ...
• 78.5k

### Selecting sublists from a ragged array of lists of strings

Select[MatchQ[{___, _?(StringMatchQ["data" ~~ ___]), ___}]] @ records ...
• 398k
Accepted

...
• 55.7k
Accepted

### Crafting a replacement rule to convert derivatives to finite differences

Aha, this question is for me. ...
• 67k
Accepted

### Switch with string patterns

Switch doesn't use the form of the first argument to somehow predict what kind of comparison you want to do. So, it doesn't automatically try a string match just ...
• 30.3k

### Why does Blank sometimes not match the empty expression?

Your pattern is actually interpreted as a multiplication: FullForm[_{_Symbol}] (* List[Times[Blank, Blank[Symbol]]] *) To match a list consisting of a Symbol, use ...
• 67.4k

### Using patterns in ReplaceAll to match different symbols

If I understand the question, then k1 and k2 (shown below) are two groups that dictate the outcomes of the dot products. ...
• 55.7k