-1

I have this code which compares a number to a number(what i called item in my code) in the domain range to see if it is already there. If it its then print to the output file if it is not then only print it once.

Question How to make sure that if the number isn't between the domain range then print only one time. ( I used true and false statements but this doesn't work because when it is false, it would print several duplicates- on the code below i am not sure how to implement so that it print the number that not in the domain range once instead of multiple times )

for item in lookup[uniprotID]:
    for varain in wholelookup[uniprotID]:
        for names in wholeline[uniprotID]:
            statement=False
    if re.search(r'\d+',varain).group(0)==item and start <= int(item) <= end:
        result = str(int(item) - start + 1)
        if varain in names.split(' '):
            statement = True
            print ">{0} | at position {1} | start= {2}, end= {3} | description: {4} | {5}".format(uniprotID, result, start, end, varain, names)
            if statement == True:
                print(''.join(makeList[start-1:end]))
4

2 に答える 2

1

これに基づく何かがあなたのために働くかもしれません:

already_seen = set()
for line in sys.stdin:
   if line not in already_seen:
      already_seen.add(line)
      sys.stdout.write(line)

ファイルが大きい場合、これを行うと大量の仮想メモリが消費される可能性があります。その場合は、anydbm またはブルーム フィルターを調べてください。

于 2012-07-24T20:29:41.490 に答える
1

範囲外の値を格納します。

stored_prints = {}

if not ( start <= int( item ) <= end ):
    try:
        stored_prints[item]++
    except:
        stored_prints[item] = 1

print stored_prints

ただし、必要に応じてフォーマットして適合させる必要がありますが、質問を正しく理解していれば、これで必要なことを行うことができます。

于 2012-07-24T20:25:17.573 に答える