- #! /usr/bin/env python3
- # ! coding:utf-8
-
- #auto detect step is negative or positive
-
- arr = list(map(lambda x: str(x).replace('\n', ''), open('series.txt', 'r')))
- result = list()
- _next = None
- nega_or_posi = (int(arr[1]) - int(arr[0])) /abs(int(arr[1]) - int(arr[0]))
- for i in range(len(arr)):
- if i != len(arr)-1 and int(arr[i].lstrip('0')) + nega_or_posi == int(arr[i+1].lstrip('0')):
- result.append(arr[i])
- _next = arr[i + 1]
- elif isinstance(_next, str):
- result.append(_next)
- _next = None
-
- print(result)
复制代码
|