MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Computing n-grams

  • To: mathgroup at
  • Subject: [mg89015] RE: [mg88913] Computing n-grams
  • From: "Coleman, Mark" <Mark.Coleman at>
  • Date: Fri, 23 May 2008 03:11:22 -0400 (EDT)
  • References: <> <>

Thanks to all MathGroup members who so promptly pointed out solutions to
my recent posting regarding n-grams.

I must (sheepishly) confess this is not the first time (nor I am sure
the last) that far more astute Mathematica users than me have pointed me towards
solutions using built-in commands.  In the future I shall endeavor to
find questions more worthy of MathGroup users' skills! *smile*



On 22 May 2008, at 03:49, Coleman, Mark wrote:

> Greetings,
> Imagine one has a list such as {a,b,c,d,e,f,g}. I'm trying to find an
> efficient way in Mathematica to compute the n-grams of the list.
> That is, for
> n=2, the n-grams are all the lists of length 2 consisting of
> consecutive elements, e.g.,
> {a,b},{b,c},{c,d},{d,e},...
> While for n=3,
> {a,b,c},{b,c,d},{c,d,e},..., and so on.
> As I understand it, the built-in Mathematica commands such as Subsets
> or Permutations compute all possible list of size n, without regard to

> the order of the list elements.
> Thanks,
> Mark

  • References:
  • Prev by Date: Re: enter key on new Mac MBP
  • Next by Date: Re: circuit grid
  • Previous by thread: Re: Computing n-grams
  • Next by thread: Re: Computing n-grams