def is_valid(id): if len(id) !=18: return False try: for i in id: if i =='x' continue elif type (eval(i))==int continue else:return False except:return False return True import csv a=[] with open('date3_id.txt','r',encoding='utf-8')as f: f_reader=csv.DictReader(f) for line in f_reader: x=line.get('身份证号码') if is_valid(x)==False continue else: line['身份证号码']=line['身份证号码'][6:10]+'-'+line['身份证号码'][10:12]+'-'+line['身份证号码'][12:14] a.append(line) b=sorted(a,key=lambda i :i['身份证']) for a in b: print(f"{a['姓名']},{a['身份证号码']}")
import random import datetime b=[] with open('data6.txt','r',encoding='utf-8') as f: data=f.read().strip('\n') a=date.split('\n') for i in a: b.append(i.split('\t')) x=random.sample(b,eval(input('输入随机抽点个数:'))) t=datetime.datetime.now() with open(t.strftime('%Y%m%d')+'.txt','w',encodiing='utf-8') as f: for i in x: f.write('\t'.join(i)) f.write('\n') print('\t'.noin(i))
import random import datetime b=[] with open('data6.txt','r',encoding='utf-8')as f: date=f.read().strip('\n') a=date.split('\n') for i in a: b.append(i.split('\t')) t=datetime.datetime.now() with open(t.strftime('%Y%m%d')+'_txt,'a',encoding='utf-8')as f: print("{:=∧30}''.format('抽点开始')) y=1 while y !=0: y=eva(input('输入随机抽点个数:')) x=random.sample(b,y) for i in x: b.remove(i) f.write('\t'.join(i)) print('\t'.join(i)) print("{:=∧30}".format('抽点结束'))