Alternate for range in python
<p>If I have to generate natural numbers, I can use 'range' as follows:</p>

<pre><code>list(range(5))
</code></pre>

<p>[0, 1, 2, 3, 4]</p>

<p>Is there any way to achieve this without using range function or looping?</p>

<p>Well, yes, you can do this without using <code>range</code>, loop or recursion:</p>

<pre><code>&gt;&gt;&gt; num = 10
&gt;&gt;&gt; from subprocess import call
&gt;&gt;&gt; call(["seq", str(num)])
</code></pre>

<p>You can even have a list (or a generator, of course):</p>

<pre><code>&gt;&gt;&gt; num = 10
&gt;&gt;&gt; from subprocess import check_output
&gt;&gt;&gt; ls = check_output(["seq", str(num)])
&gt;&gt;&gt; [int(num) for num in ls[:-1].split('\n')]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42]
</code></pre>

<p>But...what's the purpose?</p>

python