Python reads consecutive numbers

there is a column of numbers in my file, which looks like:

1
2
7
8
9
12
17
21
22
23

I want to get three consecutive numbers and output them. For example, in the above file, the result I want to get is

.
7
8
9

I would like to ask you, how should it be realized? Thank you

Mar.16,2021

first read all the data into a list, and then go through it.
for i in range (2, len (nums)):

  if nums[i] + nums[i -2] == nums[i-1] * 2:
      print()

you can also make this judgment while reading the file

it is not convenient for typing on mobile phone. The format may not be correct


read one line at a time, dynamically plan something at will, or draw a state transition picture to realize it. If you think about this topic for yourself, you will know


similar problem, understand?

Menu