Skip to content

Instantly share code, notes, and snippets.

@hombit
Created January 13, 2018 08:47
Show Gist options
  • Save hombit/24745f2ada38ddf9222713c16c955175 to your computer and use it in GitHub Desktop.
Save hombit/24745f2ada38ddf9222713c16c955175 to your computer and use it in GitHub Desktop.
import random
def words_from_file(filename):
with open(filename, encoding='utf-8') as f:
text = f.read()
text = text[1:] # Только для блокнота Windows
text = text.replace(',', '')
text = text.replace('.', '')
text = text.lower()
words = text.split()
return words
def anno(word):
a = random.sample(word, len(word))
new_word = ''.join(a)
return new_word
def create_csv_table(words, table_filename, n_anno):
with open(table_filename, 'w') as f:
for x in words:
f.write(x)
for i in range(n_anno):
f.write(';')
f.write(anno(x))
f.write('\n')
words = words_from_file('text.txt')
create_csv_table(words, 'table.csv', 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment