switch_source()用于获取文本信息
rewrite_source()用于将信息顺序轮换,其参数times表示要轮换多少次,

def switch_source():
tmp = []
with open('switch_source.txt','r') as ss:
for i in ss:
tmp.append(i.strip())
return tmp

def rewrite_source(times):
tmp = switch_source()
for i in range(times):
tmp.append(tmp[i])
for i in range(times):
tmp.remove(tmp[i - i])
with open('switch_source.txt','w') as rew_src:
for i in tmp:
rew_src.write(str(i) + '\n')

rewrite_source(2)


switch_source.txt原始内容如下:
1
2
3
4
5

轮换2次后效果为:
3
4
5
1
2


相关文章:

  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-03-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-10-18
  • 2021-06-19
  • 2021-11-01
  • 2021-08-01
相关资源
相似解决方案