实验6
2022/5/24 23:50:29
本文主要是介绍实验6,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import random n = eval(input('输入抽取数目:')) with open('C:\\Users\\肖鑫\\Desktop\\实验6数据文件\\实验6数据文件\\data5.txt','r',encoding='utf-8') as f: x = [] for line in f: x.append(line.strip('\n')) print(x) data = random.sample(x, n) for i in data: print(i) import datetime t = datetime.datetime.now() filename = t.strftime('%Y%m%d') + '.txt' print(filename) with open(filename,'a',encoding='utf-8')as f: for j in data: f.write(j)
with open('C:\\Users\\肖鑫\\Desktop\\实验6数据文件\\实验6数据文件\\data3_id.txt','r',encoding='utf-8') as f: data = f.readlines() def is_valid(x): if len(x) != 18: return False else: for i in x: if '0' <= i <= '9' or i == 'X': continue return False return True data0 =data[1::] data0=[line .rstrip('\n' ).split(',') for line in data0] data1=[] for i in range (len(data0)): if is_valid(data0[i][1])==True: data1. append(data0[i]) print(data1) for i in range(len(data1)): data2 = data1[i][0]+data1[i][1][6:14] i = i + 1 data3 = [data2[0:2],',',data2[2:6],'-',data2[6:8],'-',data2[8:10]] data4 = ''.join(data3) print(data4)
(按年龄排序用lambda函数,本人还需钻研钻研一下。待更。)
这篇关于实验6的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南