1 with open('data3_id.txt', 'r', encoding = 'utf-8') as f:
 2         datas=f.readlines()
 3         datas=[line.strip().split(',') for line in datas]
 4         data=[]
 5 def isvalid(id):
 6      if len(id)!=18: return False
 7      else:
 8          for i in id:
 9              if '0'<=i<='9'or i=='X':continue
10              return False
11          return True
12 for i in range(1,len(datas)):
13      if(isvalid(datas[i][1])):
14          data.append([datas[i][0],datas[i][1][6:10]+'-'+datas[i][1][10:12]+'-'+datas[i][1][12:14]])
15 data.sort(key=lambda x:x[1])
16 print(f'{datas[0][0]},{datas[0][1]}')
17 for line in data:
18      print(f'{line[0]},{line[1]}')

 1 with open('data5.txt','r',encoding='utf-8')as f:
 2     data1=f.read().split('\n')
 3     data2=[]
 4     for i in data1:
 5         data2.append(i.split('\t'))
 6 import random
 7 import datetime
 8 while True:
 9   n=int(input('输入随机抽点人数:'))
10   if n==0:
11       break
12   data3=[]
13   data4=[]
14   while len(data3)<n:
15       if data2[random.randint(0,len(data2)-1)] not in data3:
16           data3.append(data2[random.randint(0,len(data2)-1)])
17   for i in data3:
18       print(','.join(i))
19       data4.append(','.join(i)+'\n')
20   t=datetime.datetime.now()
21   filename=t.strftime('%Y%m%d')+'.txt'
22   with open (filename,'w',encoding='utf-8')as f:
23     f.writelines(','.join(data4))

 

posted on 2022-05-23 22:12  starry。  阅读(7)  评论(2编辑  收藏  举报