Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Python

PowerStrings problem solved in one line

power = lambda s : re.match('^(\w+?)\\1+$', s) and (len(s) / len(re.match('^(\w+?)\\1+$', s).group(1))) or 1
https://snipt.net/embed/ef12a091faf3f4403074eff1ac87e548/
https://snipt.net/raw/ef12a091faf3f4403074eff1ac87e548/
ef12a091faf3f4403074eff1ac87e548
python
Python
1
2016-11-18T06:52:36
True
False
False
/api/public/snipt/8567/
powerstrings-problem-solved-in-one-line
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="n">power</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">s</span> <span class="p">:</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">&#39;^(\w+?)</span><span class="se">\\</span><span class="s1">1+$&#39;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="s1">&#39;^(\w+?)</span><span class="se">\\</span><span class="s1">1+$&#39;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)))</span> <span class="ow">or</span> <span class="mi">1</span> </span></pre></div> </td></tr></table>
acm, power, strings
Copyrighted, illegal, or inappropriate content? Email [email protected].