7 votes

How to find the nearest element that is bigger than x?

Nearest will either give us the value we're looking for or the value to the left in a sorted list. So we can simply find the ...
Greg Hurst's user avatar
  • 35.5k
5 votes

Prepend a column of data to a given list

Using the level argument of Join Join[List /@ Range[0.1, 1, 0.1], data, 2] gives the expected result: ...
eldo's user avatar
  • 49.2k
5 votes

How to find the nearest element that is bigger than x?

If unsorted, then a straightforward procedural routine might be good: ...
Goofy's user avatar
  • 863
4 votes

How to replace an element in a list based on the value of the next element?

Using SequenceReplace list = {0, 0, 0, -1, 0}; SequenceReplace[list, {0, -1} :> Splice @ {1, -1}] {0, 0, 1, -1, 0} ...
eldo's user avatar
  • 49.2k
4 votes

How to copy with the last 1 with pattern matching method in a list?

list = {1, 2, 3, 1, 5, 8, 1, 9, 6}; Using SequenceReplace and its 3rd argument To replace from the end we have to ...
eldo's user avatar
  • 49.2k
4 votes

How do you efficiently return all of a list but one element?

An update from v13.1 worth adding here is DeleteElements With a list list = RandomInteger[{-1, 11}, 13] ...
bmf's user avatar
  • 13.3k
4 votes

Getting rid of complex numbers in a solution list

RealValuedNumberQ, which came with V 13.3, is custom-tailored for this task: ...
eldo's user avatar
  • 49.2k
3 votes

How to copy with the last 1 with pattern matching method in a list?

list = {1, 2, 3, 1, 5, 8, 1, 9, 6} Using FirstPosition: ...
Syed's user avatar
  • 42.1k
3 votes

Delete duplicates from hierarchy of lists

Using UniqueElements (new in 13.1) ...
eldo's user avatar
  • 49.2k
3 votes

How to make a pattern to match?

Using Michael's data: list = {{3, 5, 7, 5, 2}, {1, 2, 3, 4, 5}, {1, 3, 4, 5}, {1, 3, 3}}; Function definition ...
eldo's user avatar
  • 49.2k
3 votes

Measuring multiple incidences of a continuous constant in a list

Using SequenceSplit (new in 11.3) list = {{0}, {1}, {1}, {0}, {1}, {0}}; Length /@ SequenceSplit[list, {{0}}] {2, 1}
eldo's user avatar
  • 49.2k
3 votes

Adding 1 to all second elements

Supporting @eldo in an effort of good house maintenance as much as I can. We can use Query ...
bmf's user avatar
  • 13.3k
3 votes

Adding 1 to all second elements

Showing some of the newer functions list = {{{5, 1}}, {{2, 1}, {3, 1}}, {{7, 1}}, {{2, 3}}}; 1. ReplaceAt (new in 13.1) ...
eldo's user avatar
  • 49.2k
3 votes

Prepend a column of data to a given list

Using Do and PrependTo: ...
E. Chan-López's user avatar
3 votes

Prepend a column of data to a given list

data= {{3, 4}, {5, 1}, {5, 2}, {1, 8}, {9, 5}, {7, 6}, {25, 15}, {1, 2}, {55, 0}, {10, 1}}; ...
user1066's user avatar
  • 15.6k
3 votes

Translate selection from one list to another

KeySelect is another possibility al = {1, 2, 3, 4, 5, 6}; bl = {a, b, c, d, e, f}; KeySelect[EvenQ] @ Thread[al -> bl] <...
eldo's user avatar
  • 49.2k
2 votes

How to replace an element in a list based on the value of the next element?

Using ReplacePart and Position: ...
E. Chan-López's user avatar
2 votes

How to replace an element in a list based on the value of the next element?

We can, also, use SequencePosition+ReplaceAt ...
bmf's user avatar
  • 13.3k
2 votes

Splitting up delimited data in lists

list = {"section 1", "a", "b", "c", "section 2", "d", "e", "f"}; A slot-free ...
eldo's user avatar
  • 49.2k
2 votes

How do you efficiently return all of a list but one element?

list = {3, 6, 9, 12, 6}; There are, of course, many more possibilities. Some of them are: Operator form of DeleteCases ...
eldo's user avatar
  • 49.2k
2 votes

Prepend 0 to sublists

It's a bit strange for me that no answer used Riffle With list = RandomInteger[{1, 9}, {4, 5}]; zero = 0~ConstantArray~{Length@list}; we do: ...
bmf's user avatar
  • 13.3k
2 votes

Prepend 0 to sublists

Using Cases: ...
E. Chan-López's user avatar
2 votes

Improving a selection routine

Using the third argument of GroupBy: ...
E. Chan-López's user avatar
2 votes

Improving a selection routine

Because Chris also asked about Associations: ...
eldo's user avatar
  • 49.2k
2 votes

Max function used with nested lists

Using GroupBy and Max: ...
E. Chan-López's user avatar
2 votes

Max function used with nested lists

list = {{{1, 5, 6}, {4, 7, 8}}, {{1, 2, 2}, {5, 6, 7}}}; 1. With ArrayReduce (new in 12.2) ...
eldo's user avatar
  • 49.2k
2 votes

Adding 1 to all second elements

Using Cases and Map: ...
E. Chan-López's user avatar
2 votes

Measuring multiple incidences of a continuous constant in a list

Since @eldo and @E. Chan-López revived this thread a very small contribution to their efforts. list = {{0}, {1}, {1}, {0}, {1}, {0}}; then ...
bmf's user avatar
  • 13.3k
2 votes

Measuring multiple incidences of a continuous constant in a list

Using SplitBy and DeleteCases: ...
E. Chan-López's user avatar
2 votes

How to make a pattern to match?

Using SequenceReplace: ...
Syed's user avatar
  • 42.1k

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