Chinaunix

标题: python字典处理案例 [打印本页]

作者: ma3501406    时间: 2018-01-16 11:34
提示: 作者被禁止或删除 内容自动屏蔽
作者: jason680    时间: 2018-01-16 11:57
回复 1# ma3501406

http://bbs.chinaunix.net/thread-4290275-1-1.html

作者: zxy877298415    时间: 2018-01-16 16:06
本帖最后由 zxy877298415 于 2018-01-16 16:17 编辑

回复 1# ma3501406

python 3


  1. import re
  2. with open ('file.txt') as f,open ('file1.txt') as f1:
  3.     l=f1.readlines()
  4.     s = 0
  5.     for i in f:
  6.         t=re.split(' +',i)
  7.         for j in range(0,11-int(t[1])):
  8.             if s == len(l):break
  9.             print (t[0]+"  "+l[s], end='')
  10.             s += 1
复制代码






欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2