tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
11
Task/Semordnilap/Python/semordnilap-1.py
Normal file
11
Task/Semordnilap/Python/semordnilap-1.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>>> with open('unixdict.txt') as f:
|
||||
wordset = set(f.read().strip().split())
|
||||
|
||||
>>> revlist = (''.join(word[::-1]) for word in wordset)
|
||||
>>> pairs = set((wrd, rev) for wrd, rev in zip(wordset, revlist)
|
||||
if wrd < rev and rev in wordset)
|
||||
>>> len(pairs)
|
||||
158
|
||||
>>> sorted(pairs, key=lambda p: (len(p[0]), p))[-5:]
|
||||
[('damon', 'nomad'), ('lager', 'regal'), ('leper', 'repel'), ('lever', 'revel'), ('kramer', 'remark')]
|
||||
>>>
|
||||
Loading…
Add table
Add a link
Reference in a new issue