daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Sep 14th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Первая задача
  2. ----------------------------------------------
  3. from nltk.tokenize import sent_tokenize
  4. from nltk import FreqDist
  5. import pymystem3
  6. import re
  7.  
  8. f = open('text', 'r')
  9. text = f.read()
  10.  
  11. words = pymystem3.Mystem().analyze(text)
  12. names = []
  13.  
  14. for word in words:
  15.     if word.get('analysis'):
  16.         for an in word['analysis']:
  17.             if 'S,имя,жен' in an['gr']:
  18.                 names += [an['lex']]
  19.                 break
  20.  
  21.  
  22. print(w_names)
  23. print(FreqDist(w_names))
  24.  
  25.  
  26. Вторая задача
  27. ----------------------------------------------
  28. import re
  29.  
  30. string =  'AA001A777'
  31.  
  32. letters = 'ABCEKMHOPTXY'
  33.  
  34. def check(numb):
  35.     if re.match('^[%s]{1}[0-9]{2}[1-9]{1}[%s]{2}[1-9]?[0-9]{1}[1-9]{1}$' % (letters, letters), numb):
  36.         return 'gen'
  37.     elif re.match('^[%s]{2}[0-9]{2}[1-9]{1}[%s]{1}[1-9]?[0-9]{1}[1-9]{1}$' % (letters, letters), numb):
  38.         return 'tr'
  39.     else:
  40.         return 'incorrect'
  41.  
  42. print(check(string))
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