Home>

I am doing some text analysis with pymorphy2. From the analysis, I extract the word itself (parse.normal_form) and its part of speech (parse.tag.POS).

This is what I get

appearance of NOUN
UN NOUN
be VERB
condition PRTS
whole ADJF

How can you write all this into a list that contained many small lists

[['appearance', 'NOUN'], ['un', 'NOUN'], ['be', 'VERB']]
words= text.split ()
pos_tag= []
for word in words:
  parse= morph.parse (word) [0]
  print (parse.normal_form, parse.tag.POS)
  • Answer # 1

    This is very easy to do, just create an empty list and add a list of two values ​​to it:

    words= text.split ()
    res= []
    for word in words:
      parse= morph.parse (word) [0]
      res.append ([parse.normal_form, parse.tag.POS])
    print (res)
    

    Conclusion:

    [['appearance', 'NOUN'], ['un', 'NOUN'], ['be', 'VERB']]
    
  • Answer # 2

    This is very easy to do, just create an empty list and add a list of two values ​​to it:

    words= text.split ()
    res= []
    for word in words:
      parse= morph.parse (word) [0]
      res.append ([parse.normal_form, parse.tag.POS])
    print (res)
    

    Conclusion:

    [['appearance', 'NOUN'], ['un', 'NOUN'], ['be', 'VERB']]