with open('data6_1.txt','r',encoding='utf-8') as f: t=[] for line in f.readlines(): m=line.strip().split() t.append(m) t.sort(key=lambda l:l[2],reverse=True) with open('data6_2.txt','w+',encoding='utf-8') as n: for i in t: n.write(' '.join(i)+'\n')
import random def get_lucky_boy(lis:list,trys:int): result=[] for i in range(trys): boy=random.choice(lis) lis.remove(boy) result.append(boy) t=[] for i in result: t.append(' '.join(i)+'\n') return ''.join(t) ls=[] with open('data7.txt','r',encoding='utf-8') as f: for line in f.readlines(): m=line.strip().split() ls.append(m) n=int(input('yikutu desuka?')) boys=get_lucky_boy(lis=ls,trys=n) print(boys) with open('lucky.txt','w',encoding='utf-8') as nf: nf.write(boys)
import datetime import random def get_lucky_boy(lis:list,trys:int): result=[] for i in range(trys): boy=random.choice(lis) lis.remove(boy) result.append(boy) return result def ls2str(ls:list): t=[] for i in ls: t.append(' '.join(i)+'\n') return ''.join(t) ls=[] with open('data7.txt','r',encoding='utf-8') as f: ls = [] with open('data7.txt', 'r', encoding='utf-8') as f: for line in f.readlines(): m = line.strip().split() ls.append(m) n=int(input('yikutudesuka?')) boys=get_lucky_boy(lis=ls,trys=n) result=ls2str(boys) print(result) filename=datetime.datetime.now().strftime('%Y%m%d') with open(filename,'w',encoding='utf-8') as nf: nf.write(result)