Python read input lines through function call
<p>My code below works perfectly to receive my input data (list.txt) and return lines between 2 and 5 to the screen. </p>

<pre><code>def get_list():

    file = open('list.txt', 'r')
    lines = file.read().splitlines()[2:5]
    print (lines)

get_list()
</code></pre>

<p>However I am required to implement something where I can call the function like:</p>

<pre><code>get_list()[2:5] 
</code></pre>

<p>and this would print between lines 2 and 5 instead. Can anyone suggest a possible way I can do this?  Thanks!</p>

<p>Just return lines !</p>

<pre><code>def get_list():

    file = open('list.txt', 'r')
    lines = file.read().splitlines()
    return lines
</code></pre>

python file text input