Skip to main content
6 votes

Counting consecutive units in nested lists

...
eldo's user avatar
  • 74.7k
5 votes

Counting consecutive units in nested lists

Max /@ Total[(Split /@ lst), {3}] (* {2, 3, 5, 7, 13} *) ...
user1066's user avatar
  • 19.4k
5 votes

Counting consecutive units in nested lists

You could also split on the 1-sequences: Max[SequenceSplit[#, ones : {1 ..} :> Length[ones]]] & /@ list Or SequenceCases:...
lericr's user avatar
  • 29.1k
4 votes

Recovering indices from an expression

Oh dear... I was working too hard. This will do it. ...
ZeroTheHero's user avatar
4 votes
Accepted

Counting consecutive units in nested lists

Using LongestCommonSubsequence ...
vindobona's user avatar
  • 4,536
4 votes

Recovering indices from an expression

For expr = U[1, 3] U[1, 4] U[1, 5] U[2, 2] U[3, 1]; you can do {firstindex, secondindex} = Transpose[List @@@ List @@ expr] or ...
march's user avatar
  • 23.8k
3 votes

Recovering indices from an expression

Given, expression = U[1, 3] U[1, 4] U[1, 5] U[2, 2] U[3, 1] you could use Cases: ...
lericr's user avatar
  • 29.1k
3 votes

Counting consecutive units in nested lists

If we look at your problem in a simplistic manner, we could see a function that increments by receiving 1 and resets by receiving 0 (like multiplying but with an increment). Since we need the result ...
Ben Izd's user avatar
  • 9,319
3 votes

How can I construct this matrix?

n = 5; Table[RotateRight[Range[n], i], {i, 0, n - 1}] // MatrixForm ...
eldo's user avatar
  • 74.7k
3 votes

How to add zeros before and after each element in a list?

Using Splice list={0.2,0.5,0.7}; Take[Riffle[list, Splice[{0, 0}], {1, -1, 2}], {2, -2}];
RGL's user avatar
  • 61
3 votes

Get alphabetical number of characters in string

str = "abcdefghijklmnopqrstuvwxyz"; Using LetterNumber (new in 10.1) ...
eldo's user avatar
  • 74.7k
2 votes

Finding position of non empty matrix entries

list = {{}, {1, 2}, {}, {3, 4}, {}, {}, {}}; Using Position and DeleteCases ...
eldo's user avatar
  • 74.7k
2 votes

Creating a conditional table

list = {7, 0, 8, 2, 1, 5, 8, 0, 6, 7}; Using FirstPosition (new in 10.0) to catch missing values 1. The 3rd parameter of ...
eldo's user avatar
  • 74.7k
2 votes

Creating a new list from an existing one

data = { {{1, -1}, {2, 5}, {3, 9}, {4, 2}}, {{1, -4}, {2, 0}, {3, 11}, {4, -1}}, {{1, 3}, {2, 2}, {3, 22}, {4, 1}}, {{1, 0}, {2, 0}, {3, -5}, {4, 7}} }; ...
eldo's user avatar
  • 74.7k
2 votes

Construct a list from another list

lst = Range[24] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24} Using ...
E. Chan-López's user avatar
2 votes

Delete sublists of list with given properties

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

Replace elements of a list based on a function

Also: f = Table[3*k*k, {k, 1, 16}]; f^ ArrayPad[{1, 1, 1, 1, 0, 0, 0, 0}, {0, Length@f - 8}, "Periodic"] ...
vindobona's user avatar
  • 4,536
2 votes

Replace elements of a list based on a function

f = Table[3*k*k, {k, 1, 16}]; Using SequenceCases ...
eldo's user avatar
  • 74.7k
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
  • 74.7k
2 votes

How to use `StringJoin` in the given example?

list = {{"abc", "0000"}, {"def", "1111"}}; Using the operator form of Insert ...
eldo's user avatar
  • 74.7k
2 votes

How to leave only specific columns?

...
eldo's user avatar
  • 74.7k
1 vote

How to create an array from all combinations of the vector components?

la = {a, b, c}; lb = {w, x, y, z}; A variant of E. Chan-López first answer using Comap (new in 14.0) ...
eldo's user avatar
  • 74.7k
1 vote

How to make an element in a list nested within a list have a default value?

list = {{{-2, -2}, 1}, {{-2, -5}, 2, 7}, {{1, 5}, 3, 9}, {{7, -7}, 4}}; Using ReplaceAll ...
eldo's user avatar
  • 74.7k
1 vote

How do I remove parts of this data?

list = {{9.9, 0}, {"", ""}, {10.0, -21.7}, {"", ""}, {10.0, 28.5}, {"", ""}}; Using ...
eldo's user avatar
  • 74.7k
1 vote

List of symbols wherein position encoded by number to string

list = {{"a", 6}, {"z", 1}, {"g", 2}, {"y", 12}}; Using SubsetMap (new in 12.0) ...
eldo's user avatar
  • 74.7k
1 vote

How to substitute Table environments by a more sophisticated code

list = Range[12, 30]; Using SequenceCases ...
eldo's user avatar
  • 74.7k
1 vote

Find list position and mapping list

...
eldo's user avatar
  • 74.7k

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