python作业怎么交_python作业急求晚上8点前交作业

Writeamethodanagrams(f)thatopensatextfile,f,splitsitintowordsandprintsoutalistofanagramsinthefile.Recallthattwowordsareanagramsiftheyarethesameafterwesorttheirlettersalph...

Write a method anagrams(f) that opens a text file, f, splits it into words and prints out a list of anagrams in the file. Recall that two words are anagrams if they are the same after we sort their letters alphabetically. To sort the letters in a word, w, you can use this code: key = "".join(sorted([c for c in w])).

测试是这样子的。。words.txt是一个全是英文单词的txt

...

>>> anagrams('words.txt')

'emrsu': remus serum

'ceiklnrs': crinkles clinkers

'ainrst': trinas trains strain

'abbcsy': cabbys scabby

'ailprs': aprils spiral

'chins': inchs chins

'degilr': girdle glider

'giorsv': virgos vigors

'belru': bluer ruble

'aknor': akron koran

'ainst': tinas antis nitas saint stain satin

'egiinprrs': springier reprising respiring

'airstt': traits artist

'eerst': steer reste trees

'eersv': serve sever

'aceht': cheat teach

'adeprs': spared spread

'adeprt': parted depart

'eilms': smile miles

'lvx': xlv lxv

'below': elbow below

大概思路(我也不知道对不对)把每个txt导成2维数组。例如car:【0】【0】是c【0】【1】是a【0】【2】是r。然后循环回去配对。。。就是不太会写。。。。急求谢谢

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值