Given the file f, the components of which are integers. Retrieve file g formed from file f with the exception of repeated occurrences of the same number.
Here is my code
import re f = open ("f.txt","r+") n = f.read() nums = set(re.findall('-?\d+', n)) g = open("g.txt","w+") lst=[] for a in nums: lst.append(a) g.write(a) g.close() g = open('g.txt', 'r+') m = g.read() # num1= ', '.join(nums) print("Исходные числа в файле f: ",n) print("Числа в файле g: ",num1) g.close f.close The result of the program
Исходные числа в файле f: 234, -5 , 45, 2, 234, 0, 0 Числа в файле g: 0, 234, -5, 2, 45 The program works, but you need to redo it so that f.read () is not in the variable n. You also need to make the input numbers in the fc file keyboard. How can I change the code to fix these problems?