Skip to main content
5 votes
Accepted

How to make valid expressions with arbitrary number of named Blanks?

Not sure exactly how you want to use this, but the built in Distribute can do the work for you: ...
lericr's user avatar
  • 30.2k
3 votes

Change part of a list

Using SequenceSplit (new in 11.3) f = Flatten @ SequenceSplit[#, {1, 2, 1} :> {2, 1, 2}] &; lis1 ...
eldo's user avatar
  • 77.9k
3 votes

Replace zeros in a list with last nonzero value

list = {-1, -1, 0, 1, 0, 0, -1, -1, 1, 1, 1, 0, 0, 0, -1}; Using SequenceSplit with ...
eldo's user avatar
  • 77.9k
3 votes

StringContainsQ, but anywhere in order

A variant of NewStringContainsQFunction using StringPosition: ...
E. Chan-López's user avatar
3 votes

StringContainsQ And

list = {"abcd", "cdab", "acdb", "abdc"}; Using MapThread and ...
eldo's user avatar
  • 77.9k
3 votes

Put edges of a matrix to zero

a = Array[1 &, {5, 7}]; Border positions p = {{All, 1}, {All, -1}, {1, All}, {-1, All}}; Using `ReplaceAt (new in 13.1) <...
eldo's user avatar
  • 77.9k
2 votes

Put edges of a matrix to zero

Just another way and @kglr example: ...
ubpdqn's user avatar
  • 62k
2 votes

How to write a rule that matches alternatives but return one of them always?

I really don't think that the duplication is egregious in this case, but you could avoid it with something like this: ...
lericr's user avatar
  • 30.2k
2 votes

How to make valid expressions with arbitrary number of named Blanks?

You can always use ReplaceRepeated (//.): ...
march's user avatar
  • 23.9k
2 votes

How to return a default value if no match is found in search of string

Using SequenceSplit (new in 11.3) ...
eldo's user avatar
  • 77.9k
2 votes

Creating rule-based sublists

...
eldo's user avatar
  • 77.9k
2 votes

Removing lists with zero at any position

list = Tuples[Range[-2, 2], 2]; Using Pick and ContainsNone (new in 10.2) ...
eldo's user avatar
  • 77.9k
2 votes

StringContainsQ And

list = {"abcd", "cdab", "acdb", "abdc"}; Using SequenceCases and ...
eldo's user avatar
  • 77.9k
2 votes

StringContainsQ, but anywhere in order

c = Characters["aabbckkdf"]; s = Characters["acd"]; Using DeleteElements (new in 13.1) ...
eldo's user avatar
  • 77.9k
2 votes

Finding words that start and end with same letter

res = Cases[WordList[], x_ /; StringTake[x, 1] == StringTake[x, -1]]; // AbsoluteTiming // First 0.033042 res // Length ...
eldo's user avatar
  • 77.9k
2 votes

Replacing a sub-partition (unordered list; multiset)

list = {{4, 4, 2, 2, 1, 1, 1}, {4, 4, 2, 2, 2, 1}}; A variant of 1066's answer using SequenceReplace (new in 11.3) ...
eldo's user avatar
  • 77.9k
2 votes

Replace number in string with ? and /;

list = {"A4", "A#3"}; Map[StringJoin, Characters[list] /. {"A", d_?DigitQ, ___} :> {"B", d}] {"B4", "A#...
eldo's user avatar
  • 77.9k
1 vote

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}}}}; Using ReplacePart <...
eldo's user avatar
  • 77.9k
1 vote

Why does ReplaceRepeated work differently in numerator and denominator?

expr = 1/(a Sqrt[b]); Using NumeratorDenominator (new in 12.0) ...
eldo's user avatar
  • 77.9k
1 vote

Creating rule-based sublists

Using Association and Merge ...
ubpdqn's user avatar
  • 62k
1 vote

How to return a default value if no match is found in search of string

Using s1 = "a-1_b-2_c-3_d-4"; s2 = "a-1_d-4"; Rule @@@ StringSplit[#, "-"] &@StringSplit[s1, "_"] will deal with first ...
ubpdqn's user avatar
  • 62k
1 vote

Put edges of a matrix to zero

A variant using BoxMatrix ...
vindobona's user avatar
  • 4,921
1 vote

How to apply ReplaceAll to denominator?

expr = y/x^2; Using NumeratorDenominator (new in 12.0) ...
eldo's user avatar
  • 77.9k
1 vote

Sublist pattern matching

list = {{1, 2, 3}, {1, 2, 3}, {1, 2, 2, 3}, {1, 3, 3, 5}}; Using SequenceSplit (new in 11.3) ...
eldo's user avatar
  • 77.9k

Only top scored, non community-wiki answers of a minimum length are eligible