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

Why part is explained nicely in @ciao's answer. This post deals with the part:

I want to detect whether this list has repeated element a,a or b,b

You can get what expectyou expected to get from Cases[...] using the new-in-v-10 function SequenceCases:

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}

Or, define a Boolean function that returns True when the input list contains repeated elements:

containsRepeatedQ = SequenceCases[#,{Repeated[x_,{#2}]}] != {}&;

containsRepeatedQ[{a,b,a,b,a,b,a,b}, 2]

False

containsRepeatedQ[{a,b,a,b,a,b,a,a,b}, 2]

True

Why part is explained nicely in @ciao's answer. This post deals with the part:

I want to detect whether this list has repeated element a,a or b,b

You get what expect to get from Cases[...] using the new-in-v-10 function SequenceCases:

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}

Or, define a Boolean function that returns True when the input list contains repeated elements:

containsRepeatedQ = SequenceCases[#,{Repeated[x_,{#2}]}] != {}&;

containsRepeatedQ[{a,b,a,b,a,b,a,b}, 2]

False

containsRepeatedQ[{a,b,a,b,a,b,a,a,b}, 2]

True

Why part is explained nicely in @ciao's answer. This post deals with the part:

I want to detect whether this list has repeated element a,a or b,b

You can get what you expected to get from Cases[...] using the new-in-v-10 function SequenceCases:

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}

Or, define a Boolean function that returns True when the input list contains repeated elements:

containsRepeatedQ = SequenceCases[#,{Repeated[x_,{#2}]}] != {}&;

containsRepeatedQ[{a,b,a,b,a,b,a,b}, 2]

False

containsRepeatedQ[{a,b,a,b,a,b,a,a,b}, 2]

True

added 288 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Why part is explained nicely in @ciao's answer. This post deals with the part:

I want to detect whether this list has repeated element a,a or b,b

You get what expect to get from Cases[...] using the new-in-v-10 function SequenceCases:

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}

Or, define a Boolean function that returns True when the input list contains repeated elements:

containsRepeatedQ = SequenceCases[#,{Repeated[x_,{#2}]}] != {}&;

containsRepeatedQ[{a,b,a,b,a,b,a,b}, 2]

False

containsRepeatedQ[{a,b,a,b,a,b,a,a,b}, 2]

True

I want to detect whether this list has repeated element a,a or b,b

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}

Why part is explained nicely in @ciao's answer. This post deals with the part:

I want to detect whether this list has repeated element a,a or b,b

You get what expect to get from Cases[...] using the new-in-v-10 function SequenceCases:

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}

Or, define a Boolean function that returns True when the input list contains repeated elements:

containsRepeatedQ = SequenceCases[#,{Repeated[x_,{#2}]}] != {}&;

containsRepeatedQ[{a,b,a,b,a,b,a,b}, 2]

False

containsRepeatedQ[{a,b,a,b,a,b,a,a,b}, 2]

True

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

I want to detect whether this list has repeated element a,a or b,b

list={a,b,a,b,b,b,a,b,a,a,b};
SequenceCases[list,{Repeated[x_,{2}]}]

{{b, b}, {a, a}}