Search code examples
pythonpython-3.xloopsfor-loopnlp

How to extract only the desired text using for loop


So I have list of Tibetan words with their POS tag as shown below:

ད་གདོད DET
ད་གཟོད PART
ད་ཏྲིག NO_POS
ད་དུང PART
ད་དྲག NOUN

How can I strip out these POS tags and output only the below:

ད་གདོད
ད་གཟོད
ད་ཏྲིག 
ད་དུང 
ད་དྲག 

Solution

  • [x.split(" ")[0] for x in list_]
    

    returns

    ['ད་གདོད', 'ད་གཟོད', 'ད་ཏྲིག', 'ད་དུང', 'ད་དྲག']
    

    if you want printing then this:

    for x in list_:
        print(x.split(" ")[0])
    

    prints out:

    ད་གདོད
    ད་གཟོད
    ད་ཏྲིག
    ད་དུང
    ད་དྲག