1 def is_valid(a):
2     if len(a) == 18:
3         if a[-1] == 'Y':
4             return False
5         else:
6             return True
7     else:
8         return False
9
10
11 with open('data3_id.txt','r',encoding='utf-8')as f:
13     b = a.pop(0)
14
15 x = []
16 for i in a:
17     x.append(i.split(","))
18 y = []
19 for e in x:
20     if is_valid(e[1]) == True:
21         y.append(e)
22 y.sort(key = lambda x:int(x[1][6:10]))
23 print(y)
24 for i in y:
25     print(f'{i[0]},{i[1][6:10]}-{i[1][10:12]}-{i[1][12:14]}')
26
27         

 1 import random
2 import datetime
3
4 with open('data5.txt','r',encoding = 'utf-8')as f:
6 data=[i.split()for i in data]
7 n=eval(input('输入随机抽点人数：'))
8 list=random.sample(data,n)
9 for i in range(len(list)):
10     print(list[i][0]+'\t'+list[i][1]+'\t'+list[i][2])
11 t=datetime.datetime.now()
12 filename=t.strftime('%Y%m%d')+'.txt'
13 with open(filename,'w',encoding='utf-8')as f:
14     for i in range(len(list)):
15         f.write(list[i][0]+'\t'+list[i][1]+'\t'+list[i][2]+'\n')

 1 import random
2 import datetime
3 with open('data5.txt','r',encoding='utf-8')as f:
5 data=[i.split()for i in data]
6 a=[]
7 n=1
8 while n!=0:
9     n=eval(input('输入随机抽点人数：'))
10     list=random.sample(data,n)
11     for i in range(len(list)):
12         print(list[i][0]+'\t'+list[i][1]+'\t'+list[i][2])
13         data.remove(list[i])
14         a.append(list[i])
15 t=datetime.datetime.now()
16 filename=t.strftime('%Y%m%d')+'.txt'
17 with open(filename,'w',encoding='utf-8')as f:
18     for i in range(len(a)):
19         f.write(a[i][0]+'\t'+a[i][1]+'\t'+a[i][2]+'\n')