pass python lists tp methods
<p>I want to read a file and create a list from one of its columns by split() method and pass on this list to another method. Can someone explain what is the most pythonic way to achieve that ??</p>

<pre><code>def t(fname):
     k = []
     with open(fname, 'rU') as tx:
         for line in tx:
             lin = line.split()
             k.append(lin[1])
             res = anno(k)
             for id in res.items():
                  if i &gt; 0.05:
                      print(i)
</code></pre>

<p>I want to pass elements of 'k' as one list to anno() method. But in this way, I have number of lists but not one (required). </p>

<p>instead of appending to that list one by one why don't you just have a loop for that particular statement like <code>k = [(line.split())[1] for line in tx]</code>.</p>

<p>And instead of using <code>with open(file) as:</code> I have used <code>tx = open(file)</code> so whenever you have it's need you can use it and close it using tx.close() , it eliminate that that extra level of intendation.</p>

<pre><code>def t(fname):
   k = []
   tx = open(fname, 'rU')
   k = [(line.split())[1] for line in tx]
   tx.close()
   res = anno(k)
   for i in res.items():
       if i &gt; 0.05:print(i)
</code></pre>

python list methods