Source

blade / docs / _build / html / xslice.html

Full commit


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>blade.xslice &mdash; blade  documentation</title>
    
    <link rel="stylesheet" href="_static/haiku.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/print.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/theme_extras.js"></script>
    <link rel="top" title="blade  documentation" href="index.html" />
    <link rel="prev" title="blade.xreduce" href="xreduce.html" /> 
  </head>
  <body>
      <div class="header"><img class="rightlogo" src="_static/knife-smaller.png" alt="Logo"/><h1 class="heading"><a href="index.html">
          <span>blade  documentation</span></a></h1>
        <h2 class="heading"><span>blade.xslice</span></h2>
      </div>
      <div class="topnav">
      
        <p>
        «&#160;&#160;<a href="xreduce.html"><tt class="docutils literal docutils literal docutils literal"><span class="pre">blade.xreduce</span></tt></a>
        &#160;&#160;::&#160;&#160;
        <a class="uplink" href="index.html">Contents</a>
        </p>

      </div>
      <div class="content">
        
        
  <div class="section" id="module-blade.xslice">
<span id="blade-xslice"></span><h1><a class="reference internal" href="#module-blade.xslice" title="blade.xslice"><tt class="xref py py-class docutils literal"><span class="pre">blade.xslice</span></tt></a><a class="headerlink" href="#module-blade.xslice" title="Permalink to this headline"></a></h1>
<p><tt class="xref py py-class docutils literal"><span class="pre">blade</span></tt> slicing operations</p>
<dl class="function">
<dt id="blade.xslice.xat">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xat</tt><big>(</big><em>iterable</em>, <em>n</em>, <em>default=None</em><big>)</big><a class="headerlink" href="#blade.xslice.xat" title="Permalink to this definition"></a></dt>
<dd><p><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">Slice</em></a> off items in <cite>iterable</cite> found at index <cite>n</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></li>
<li><strong>n</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) &#8211; index of some items in <cite>iterable</cite></li>
<li><strong>default</strong> &#8211; default returned if nothing is found at <cite>n</cite></li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xat</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># default behavior</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">xat</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># return default value if nothing found at index</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">xat</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span>
<span class="go">11</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xchoice">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xchoice</tt><big>(</big><em>iterable</em><big>)</big><a class="headerlink" href="#blade.xslice.xchoice" title="Permalink to this definition"></a></dt>
<dd><p>Randomly <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">slice</em></a> off <strong>one</strong> items in <cite>iterable</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xchoice</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xchoice</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]))</span> 
<span class="go">3</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xdice">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xdice</tt><big>(</big><em>iterable</em>, <em>n</em>, <em>fill=None</em><big>)</big><a class="headerlink" href="#blade.xslice.xdice" title="Permalink to this definition"></a></dt>
<dd><p><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">Slice</em></a> one <cite>iterable</cite> items in <cite>iterable</cite> into <cite>n</cite> iterable items in
<cite>iterable</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></li>
<li><strong>n</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) &#8211; number of items in <cite>iterable</cite> per slice</li>
<li><strong>fill</strong> &#8211; value to pad out incomplete iterables</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xdice</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xdice</span><span class="p">([</span><span class="s">&#39;moe&#39;</span><span class="p">,</span> <span class="s">&#39;larry&#39;</span><span class="p">,</span> <span class="s">&#39;curly&#39;</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">40</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="bp">True</span><span class="p">],</span> <span class="mi">2</span><span class="p">,</span> <span class="s">&#39;x&#39;</span><span class="p">))</span>
<span class="go">[(&#39;moe&#39;, &#39;larry&#39;), (&#39;curly&#39;, 30), (40, 50), (True, &#39;x&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xfirst">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xfirst</tt><big>(</big><em>iterable</em>, <em>n=0</em><big>)</big><a class="headerlink" href="#blade.xslice.xfirst" title="Permalink to this definition"></a></dt>
<dd><p><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">Slice</em></a>  off <cite>n</cite> things from the <strong>starting</strong> end of <cite>iterable</cite> or
just the <strong>first</strong> items in <cite>iterable</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></li>
<li><strong>n</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) &#8211; number of items in <cite>iterable</cite></li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xfirst</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># default behavior</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xfirst</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
<span class="go">[5]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># first things from index 0 to 2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xfirst</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">[5, 4]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xinitial">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xinitial</tt><big>(</big><em>iterable</em><big>)</big><a class="headerlink" href="#blade.xslice.xinitial" title="Permalink to this definition"></a></dt>
<dd><p><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">Slice</em></a> off every items in <cite>iterable</cite> except the <strong>last</strong> <cite>iterable</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xinitial</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xinitial</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
<span class="go">[5, 4, 3, 2]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xlast">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xlast</tt><big>(</big><em>iterable</em>, <em>n=0</em><big>)</big><a class="headerlink" href="#blade.xslice.xlast" title="Permalink to this definition"></a></dt>
<dd><p><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">Slice</em></a> off <cite>n</cite> things from the <strong>tail</strong> end of items in <cite>iterable</cite> or
just the <strong>last</strong> items in <cite>iterable</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></li>
<li><strong>n</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) &#8211; number of items in <cite>iterable</cite> to slice off</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xlast</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># default behavior</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xlast</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c"># fetch last two things</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xlast</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="mi">2</span><span class="p">))</span>
<span class="go">[2, 1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xrest">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xrest</tt><big>(</big><em>iterable</em><big>)</big><a class="headerlink" href="#blade.xslice.xrest" title="Permalink to this definition"></a></dt>
<dd><p><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">Slice</em></a> off every items in <cite>iterable</cite> except the <strong>first</strong> item.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xrest</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xrest</span><span class="p">([</span><span class="mi">5</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">]))</span>
<span class="go">[4, 3, 2, 1]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="blade.xslice.xsample">
<tt class="descclassname">blade.xslice.</tt><tt class="descname">xsample</tt><big>(</big><em>iterable</em>, <em>n</em><big>)</big><a class="headerlink" href="#blade.xslice.xsample" title="Permalink to this definition"></a></dt>
<dd><p>Randomly <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-slice" title="(in Python v2.7)"><em class="xref std std-term">slice</em></a> off <cite>n</cite> items in <cite>iterable</cite>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>iterable</strong> &#8211; <a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterable" title="(in Python v2.7)"><em class="xref std std-term">iterable</em></a></li>
<li><strong>n</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) &#8211; sample size</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference external" href="http://docs.python.org/2.7/glossary.html#term-iterator" title="(in Python v2.7)"><em class="xref std std-term">iterator</em></a> of items</p>
</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">blade.xslice</span> <span class="kn">import</span> <span class="n">xsample</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">list</span><span class="p">(</span><span class="n">xsample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">],</span> <span class="mi">3</span><span class="p">))</span> 
<span class="go">[2, 4, 5]</span>
</pre></div>
</div>
</dd></dl>

</div>


      </div>
      <div class="bottomnav">
      
        <p>
        «&#160;&#160;<a href="xreduce.html"><tt class="docutils literal docutils literal docutils literal"><span class="pre">blade.xreduce</span></tt></a>
        &#160;&#160;::&#160;&#160;
        <a class="uplink" href="index.html">Contents</a>
        </p>

      </div>

    <div class="footer">
        &copy; Copyright 2012, L. C. Rees.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>