0

I'm totally novice in the field and I am trying to parse items in a specific column of a table and list them. I used to do this in awk which was very straight forward, but I don't know how to do it python. Here is the piece of code I've written:

for line in file('Stable7.txt','r'): genefun=line.split('\t') gene= genefun[2].rstrip() gene.split("\n\r\t") vdr=[gene] print vdr.

this put element in a separate list, while I want all items to be listed in a same list.

I'd be also grateful if someone could advise me with regard to set operations in python. If I wanna compare this list with another list how can I do it. I am looking for some command like "intersect(a,b)" in R.

RJF
  • 427
  • 5
  • 16

1 Answers1

0

Append to vdr instead of setting it each time:

vdr = []
for line in file('Stable7.txt','r'):
    genefun=line.split('\t')
    gene= genefun[2].rstrip()
    gene.split("\n\r\t")
    vdr.append(gene)
print vdr

For python list intersections, look at this SO question

Community
  • 1
  • 1
Ryan
  • 2,058
  • 1
  • 15
  • 29