tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
16
Task/Semordnilap/Python/semordnilap-2.py
Normal file
16
Task/Semordnilap/Python/semordnilap-2.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import os
|
||||
import random
|
||||
# Load file and put it to dictionary as set
|
||||
dictionary = {word.rstrip(os.linesep) for word in open('unixdict.txt')}
|
||||
|
||||
# List of results
|
||||
results = []
|
||||
for word in dictionary:
|
||||
# [::-1] reverses string
|
||||
reversed_word = word[::-1]
|
||||
if reversed_word in dictionary and word > reversed_word:
|
||||
results.append((word, reversed_word))
|
||||
|
||||
print(len(results))
|
||||
for words in random.sample(results, 5):
|
||||
print(' '.join(words))
|
||||
Loading…
Add table
Add a link
Reference in a new issue