Function to return elements from a list in Python
<p>I have a function:</p>

<pre><code>def funky(a):
    c = [4,5,6]
    return c[a]
</code></pre>

<p>I would like to be able to call:</p>

<pre><code>funky(0:1)
</code></pre>

<p>And</p>

<pre><code>funky(0,1)
</code></pre>

<p>To get the same response [4,5]. How do I modify 'funky' to do this?</p>

<pre><code>def funky(a,b):
    c = [4,5,6]
    return c[a:b+1]
</code></pre>

<p>And you can call <code>funky(0,1)</code>, And you cant't call like <code>funky(</code>0:1<code>)</code>. It's not a valid parameter.</p>

<p>You can call like <code>funky('0:1')</code> Because. If you need to take that kind of input take as string input and <code>split</code> with <code>:</code></p>

<p>like this,</p>

<pre><code>def funky(a):
        c = [4,5,6]
        x,y = map(int,a.split(':'))
        return c[x:y+1]
</code></pre>

python list