Skip to main content
deleted 5 characters in body
Source Link
Yves Klett
  • 15.5k
  • 5
  • 58
  • 125

I feel like this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one convoluted possible use of Sow and Reap.

I feel like this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one convoluted possible use of Sow and Reap.

I feel this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one convoluted possible use of Sow and Reap.

added 11 characters in body
Source Link
Yves Klett
  • 15.5k
  • 5
  • 58
  • 125

I feel like this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one convoluted possible use of Sow and Reap.

I feel like this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one possible use of Sow and Reap.

I feel like this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one convoluted possible use of Sow and Reap.

Source Link
Yves Klett
  • 15.5k
  • 5
  • 58
  • 125

I feel like this is way too complicated, but anyway:

l = {1, 2, 3, "Open", 3, 4, 5, 2, "Close", 9, 3, 4, "Open", 0, 
   "Close", "Close", 3, 5};

Reap[l //. {a___, 
     PatternSequence["Open", mid : _?NumericQ .., "Close"], 
     b___} :> {a, Sow[{mid}]; mid, b}][[2, 1]]

{{3, 4, 5, 2}, {0}}

This example might have some limited instructional value showing one possible use of Sow and Reap.