user3698773 user3698773 - 2 months ago 6
Python Question

pass python lists tp methods

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 ??

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 > 0.05:
print(i)


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).

Answer
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 > 0.05:print(i)
Comments