Skip to main content
deleted 2 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

SequenceCases:

SequenceCases[lis, {{"True", ___}, b__, c__}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Position + Part:

lis[[# ;; UpTo[# + 2]]] & /@ Flatten@Position[lis, {"True", ___}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

SequenceCases:

SequenceCases[lis, {{"True", ___}, b_, c_}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Position + Part:

lis[[# ;; UpTo[# + 2]]] & /@ Flatten@Position[lis, {"True", ___}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

SequenceCases:

SequenceCases[lis, {{"True", ___}, _, _}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Position + Part:

lis[[# ;; UpTo[# + 2]]] & /@ Flatten@Position[lis, {"True", ___}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}
added 288 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

SequenceCases:

SequenceCases[lis, {{"True", ___}, b_, c_}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Position + Part:

lis[[# ;; UpTo[# + 2]]] & /@ Flatten@Position[lis, {"True", ___}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

SequenceCases:

SequenceCases[lis, {{"True", ___}, b_, c_}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

SequenceCases:

SequenceCases[lis, {{"True", ___}, b_, c_}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Position + Part:

lis[[# ;; UpTo[# + 2]]] & /@ Flatten@Position[lis, {"True", ___}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

SequenceCases:

SequenceCases[lis, {{"True", ___}, b_, c_}]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}

Split + Cases:

Cases[p : {{"True", ___}, ___} :> Take[p, UpTo[3]]] @ Split[lis, #2[[1]] != "True" &]
{{{"True", 3, 4, 5}, {6, 5}, {3}}, {{"True", 2, 1}, {5}, {5, 6}}}