title: How to compute skipgrams in python?
body: <p>A k <a href="http://homepages.inf.ed.ac.uk/ballison/pdf/lrec_skipgrams.pdf" rel="noreferrer">skipgram</a> is an ngram which is a superset of all ngrams and each  (k-i )skipgram till (k-i)==0 (which includes 0 skip grams). So how to efficiently compute these skipgrams in python?</p>
  
  <p>Following is the code i tried but it is not doing as expected:</p>
  
  <pre><code>&lt;pre&gt;
      input_list = ['all', 'this', 'happened', 'more', 'or', 'less']
      def find_skipgrams(input_list, N,K):
    bigram_list = []
    nlist=[]
  
    K=1
    for k in range(K+1):
        for i in range(len(input_list)-1):
            if i+k+1&lt;len(input_list):
                nlist=[]
                for j in range(N+1):
                    if i+k+j+1&lt;len(input_list):
                      nlist.append(input_list[i+k+j+1])
  
            bigram_list.append(nlist)
    return bigram_list
  
  &lt;/pre&gt;
  </code></pre>
  
  <p>The above code is not rendering correctly, but print <code>find_skipgrams(['all', 'this', 'happened', 'more', 'or', 'less'],2,1)</code> gives following output</p>
  
  <blockquote>
    <p>[['this', 'happened', 'more'], ['happened', 'more', 'or'], ['more',
    'or', 'less'], ['or', 'less'], ['less'], ['happened', 'more', 'or'],
    ['more', 'or', 'less'], ['or', 'less'], ['less'], ['less']]</p>
  </blockquote>
  
  <p>The code listed here also does not give correct output:
  <a href="https://github.com/heaven00/skipgram/blob/master/skipgram.py" rel="noreferrer">https://github.com/heaven00/skipgram/blob/master/skipgram.py</a></p>
  
  <p>print skipgram_ndarray("What is your name")  gives:
  ['What,is', 'is,your', 'your,name', 'name,', 'What,your', 'is,name']</p>
  
  <p>name is a unigram!</p>