daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest May 16th, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2. import re
  3. import os
  4.  
  5. filepath = 'russian.yaml'
  6. output_dir = 'modified'
  7.  
  8. content = map(lambda s: s, open(filepath, 'rb').readlines())
  9. for i in range(len(content)):
  10.     line = content[i]
  11.     if re.match(r'^\s*\d(:|\.)(\s+\d)+\s*$', line):
  12.         for j in range((line.index(':') if ':' in line else line.index('.'))+1, len(line)):
  13.             if re.match(r'\d', line[j]) and line[j] != '0':
  14.                 modified = list(content)
  15.                 modified[i] = line[:j] + '0' + line[j+1:]
  16.                 save_path = os.path.join(output_dir, 'modified_' + str(i+1) + '_' + str(j+1) + '.yaml')
  17.                 print 'Writing', save_path
  18.                 modified_content = ''.join(modified)
  19.                 with open(save_path, 'w') as f:
  20.                     f.write(modified_content)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top