Given a text file containing integers. It is necessary to remove all even numbers from it. Tell me please.
The text in the file: "The definition of integers states that any of the numbers 1, 2, 3, 4, the number 0, and also any of the numbers 671, 256, 35 is an integer. Now we can easily give examples of integers. For example, the number 38 is an integer, the number 70040 is also an integer, zero is an integer (recall that zero is NOT a natural number, zero is an integer), the numbers 999, 1, 8, 93, 832 are also examples of integers. All integers numbers are conveniently represented as a sequence of integers, which has the following form: 0, 1, 2, 3, ... A sequence of integers can be written like this: ..., 0, 1547, 562, 35554,457,666,345,878,789. From the definition of integers, it follows that the set of natural numbers is a subset of the set of integers. Therefore, any natural number is an integer, but not any integer is a natural number. ".
I tried to do this:
file1 = open('test.txt', 'r') text1 = file1.read() import re even_num = [] new_t=[] for int_numbers in range(0, len(re.findall(r"[0-9]+", text1))): if int(re.findall(r"[0-9]+", text1)[int_numbers]) % 2 == 0: even_num.append(re.findall(r"[0-9]+", text1)[int_numbers]) for iii in range(0,len(re.split(r"\s|\,", text1))-1): if re.split(r"\s|\,", text1)[iii] not in even_num: new_t.append(re.split(r"\s|\,", text1)[iii]) print(new_t) As a result, all the even numbers were deleted, but I had difficulty with writing the result in the same file in the same format. Tell me, please.