Skip to content
Advertisement

How can i delete the repeated numbers from a file?

i need to delete numbers that are iterated more than once .. if i know the repeated numbers already. Should i have two files .. one for the real numbers i have ” data .txt “. and the other contains the numbers which are iterated ” columns.txt” .. it is just for searching quickly the repeated numbers – As the file is too huge to delete it manually so i saved the repeated numbers in a file .. how can i make right loop for searching from a file to another file and if it find it .. just delete the repeated and keep one of them only the code i tried to implement like

JavaScript

but still have a problem .. the loop deleted all numbers that are iterated and i need to keep one of them only .. not delete all repeated

JavaScript

it should be like this

JavaScript

i need to delete the number if it appears only sequentially

Advertisement

Answer

If you are on python 3.6+ then this solution will work for you. This way you dont need to have a list where you already know the repeated numbers, python will do that for you.

If you are not using python 3.6+ then change dict.fromkeys to collections.OrderedDict.fromkeys.

JavaScript

Output

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement