AnswerBun.com

How to print specific words from a sentence

Im trying to work on my English class and i was trying to take out a specific pronoun from a sentence so i want to choose the pronoun like: demonstrative and use if statements to printout only the demonstrative pronouns from the sentence and i can only find this:

**# initializing list
test_list = ["There is a weekend tomorrow", "This is a simple String", "This is only for demonstration of what i got", "Please help"]
# printing original list
print("The original list is : " + str(test_list))
# initializing K
K = "T"
res = [ele for temp in test_list for ele in temp.split() if ele[0].lower() == K.lower()]
# printing result
print("The filtered elements : " + str(res))**

It only prints the words starting with T but i want specific words like a pronoun so please help

Stack Overflow Asked by ASTRONOMICAL on February 22, 2021

1 Answers

One Answer

i found the answer when i made some simpler code that can get me the number of pronouns and i asked for an answer so someone helped me here is the code:

print("Noun Counter")
sentence = input("Write A sentence: ")
pronoun = (input("Choose a pronoun from Demonstrative, interrogative and indefinite: "))


if pronoun == "Demonstrative":
    source = sentence
    pronouns = ["this", "that", "these", "those"]
    print("Number of Demonstrative pronouns: ")
    count = dict(zip(pronouns, [0]*len(pronouns)))  # addition
    words = source.split()
    for w in words:
        if w.lower() in pronouns:
            count[w.lower()] += 1  # addition
    print(count)

elif pronoun == "Indefinite":
    source = sentence
    pronouns = ["Another", "anybody", "anyone", "anything", "each", "either", "enough", "everybody", "everyone",
                "everything", "little", "much", "neither", "nobody", "no one", "nothing", "one", "other", "somebody",
                "something", "Both", "few", "fewer", "many", "others", "several", "All", "any", "more", "most",
                "someone", "none", "some", "such"]  # download a list from somewhere
    print("Number of Indefinite pronouns: ")
    count = dict(zip(pronouns, [0]*len(pronouns)))  # addition
    words = source.split()
    for w in words:
        if w.lower() in pronouns:
            count[w.lower()] += 1  # addition
    print(count)

elif pronoun == "Interrogative":
    source = sentence
    pronouns = ["who", "whom", "whose", "what", "which"]
    print("Number of Interrogative pronouns: ")
    count = dict(zip(pronouns, [0]*len(pronouns)))  # addition
    words = source.split()
    for w in words:
        if w.lower() in pronouns:
            count[w.lower()] += 1  # addition
    print(count)

else:
    print("No pronoun found named: " + pronoun + ", please try again")

Thanks for all your help anyways. Wherever it says #addition thats where i got help.

Answered by ASTRONOMICAL on February 22, 2021

Add your own answers!

Related Questions

from and to ranges in mysql

2  Asked on January 8, 2021 by rae-ian

       

Can’t activate workbook by variable

1  Asked on January 8, 2021 by rainbowthug

   

C++17 static template lazy evaluation

4  Asked on January 8, 2021 by gcalin

     

Docker images and modules

0  Asked on January 8, 2021 by stavros-koureas

         

Rotating and moving object (follow into mouse) – Javascript

0  Asked on January 8, 2021 by karlos-margaritos

 

Method scrollToItemAtIndexPath is not working on iOS 14

3  Asked on January 7, 2021 by david-vittori

       

Adding horizontal gradient to borderline

1  Asked on January 7, 2021 by tarvo-mesepp

 

How to use flags with python’s regular expressions in string notation?

1  Asked on January 7, 2021 by werner-germn-busch

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.