how to prevent duplicate text in the output file while using for loop

2024/11/17 5:47:20

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=Falseif 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 = Trueprint ">{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]))
Answer

Something based on this might work for you:

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

Not that if your files are large, you could end up consuming a lot of Virtual Memory doing this. If so, look into anydbm or a bloom filter.

https://en.xdnf.cn/q/118843.html

Related Q&A

How to replace \\ with \ without raising an EOL error?

I am reading from a file that contains byte data but when I open the file and store the readline data into a variable it stores it in a string with backslash escapes, So when trying to decode that data…

How to find duplicates in pandas dataframe

Editing. Suppose I have the following series in pandas:>>>p 0 0.0 1 0.0 2 0.0 3 0.3 4 0.3 5 0.3 6 0.3 7 0.3 8 1.0 9 1.0 10 1.0 11 0.2 12 0.2 1…

i have error eol while scanning string literal

i dont know what is the problem im junior on python programer what happened on my code i study but i dnt understand this #fungsi coveragedef coverage ():print("[1] Kota Besar)print("[2] Kota…

How to extract specific data from JSON?

I cant seem to extract specific data from JSON which I retrieved from a link. I wrote this code and seems to work fine up to x [print(x) that is] as you can see from the screenshot-1. But, its giving e…

python csv: getting subset

here is a snapshot of my csv:alex 123f 1 harry fwef 2 alex sef 3 alex gsdf 4 alex wf35 6 harry sdfsdf 3i would like to get the subset of this data where the occurrence of a…

Variable within a Variable in Python (3)

My head is probably in the wrong place with this, but I want to put a variable within a variable.My goal for this script is to compare current versions of clients software with current software version…

selenium scraping data using children of elements

Hi im trying to scrape some data from a live stocks website. I want to display the companies name and stock price, %change ect. The details of 25 companies are shown per page, and these details follow …

Python - ETFs Daily Data Web Scraping

Im trying to web scrape some daily info of differents ETFs. I found that https://www.marketwatch.com/ have a accurate info. The most relevant info is the open Price, outstanding shares, NAV, total asse…

How to create DataFrame with columns based on scraped data?

import requests, re from bs4 import BeautifulSoupdata = []soup = BeautifulSoup(requests.get(https://www.booking.com/searchresults.html?label=gen173nr-1FCAEoggI46AdIM1gEaGyIAQGYATG4ARfIAQzYAQHoAQH4AQKI…

How do i change the colour of a button border tkinter

How do i change the colour of a border in tkinterI have looked at other solutions which recommended using highlightcolor and highlightbackground, however these did not work. excercises_button = Button(…