- 论坛徽章:
- 0
|
a.txt- 123456789
- 987654321
- qwertyui90o
- 123456789
- 987654321
- iotmhgntk
- iotmhgntk
- 123456789
- 987654321
- qwertyui90o
- 123456789
- 987654321
- iotmhgntk
- 987654321
- iotmhgntk
- aabbccdde
- 123456789
- 987654321
- qwertyui90o
- 123456789
- 987654321
- iotmhgntk
- iotmhgntk
复制代码 a.py- #coding=utf-8
- result = []
- addflag = 1
- delflag = 1
- mstr = 'aabbccdde'
- fp = open('a.txt', 'r')
- for line in fp:
- line = line.strip()
- if len(result) >= 3 and delflag == 1:
- del(result[0])
-
- if addflag == 1:
- result.append(line)
- if line == mstr:
- delflag = 0
- if len(result) >= 5:
- addflag = 0
- fp.close()
- print result
复制代码- D:\>python a.py
- ['987654321', 'iotmhgntk', 'aabbccdde', '123456789', '987654321']
复制代码 |
|