Develop a script using NLTK to prompt for a word and determine if it appears more often as a Noun or a Verb in the Brown corpus

import nltk
from nltk.corpus import brown
input_word = input("Please type a word:")
tagged_words = brown.tagged_words()
for current_word in tagged_words:
    if 

This is how my code begins, but unfortunately I am stuck here.

Answer №1

Here's a helpful tip:

print(words[0:9])

will show you:

[('The', 'AT'), ('Fulton', 'NP-TL'), ('County', 'NN-TL'), ('Grand', 'JJ-TL'), ('Jury', 'NN-TL'), ('said', 'VBD'), ('Friday', 'NR'), ('an', 'AT'), ('investigation', 'NN')]

This is a list of tuples, with the word (token) as the first value and the token type as the second.

so you could do:

for word in words:
    if word[0] == user:
        # do something based on the value of word[1]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating through monthly and yearly data in an extensive Python Pandas dataframe

Currently, I am developing a program to analyze 324 NetCDF files containing latitudes, longitudes, times, and sea surface temperature (SST) values from January 1994 to December 2020. The objective is to determine the average monthly SST within a specified ...

Exploring the manual functions of Selenium

When running tests in Selenium, I often find myself manually clicking and entering data in the fields of my browser. Is there a way to capture and save these manual actions as logs? I'm curious to see exactly what actions the user takes during a manu ...

Divide a sequence of size N into smaller subsequences so that the total sum of each subarray is below a given value M. Ensure that the cut made minimizes the sum of the maximum element

Consider an integer array sequence a_n of length N. The goal is to divide the sequence into multiple parts, each consisting of consecutive integers from the original sequence. Each part should meet the following criteria: The sum of each part must not ex ...

URLs not being gathered by the web scraping tool

Currently involved in scraping data from this specific website to compile a database. Previously, I had functioning Python code available on GitHub that successfully accomplished this task. However, due to a major overhaul in the HTML structure of the site ...

Utilize df columns for interactive interaction and apply a filtering operation using a string matching statement

Picture a dataset with several columns, all beginning with carr carr carrer banana One Two Three Is there a way to filter out only the column names that start with "carr"? Desired outcome carr carrer One Two Example dataframe: import pan ...

The unexpected issue concerning frameworks within PIL

While attempting to install PIL on my Mac OSX, I run sudo python setup.py install and everything seems to be going smoothly until I receive the following output. Has anyone else encountered this issue before? running build_ext --- using frameworks at /S ...

Header: Inconsistency in count results when using Python's itertools.groupby for printing counts only

Working on utilizing Python's itertools.groupby to calculate consecutive instances of elements in a particular way as shown below from itertools import groupby data = [1, 1, 3, 2, 3, 3, 4, 5, 5] sorted_data = sorted(data) groups = groupby(sorted_data ...

Spider login page

My attempt to automate a log in form using Scrapy's formrequest method is running into some issues. The website I am working with does not have a simple HTML form "fieldset" containing separate "divs" for the username and password fields. I need to id ...

Transform Python code into Scala

After transitioning from Python to Scala, I found myself struggling with the conversion of a program. Specifically, I encountered difficulties with two lines of code pertaining to creating an SQL dataframe. The original Python code: fields = [StructField ...

What is the method for incorporating a main title to a matplotlib figure containing subplots?

It appears that you have the capability to include a title for each subplot, as explained in this discussion: How to add title to subplots in Matplotlib? Is there a method to incorporate an overarching title in addition to the individual subplot titles? ...

Issue with pandas dataframe not displaying all columns in the final HTML table after rendering

Below are the values from df being written into an HTML template. However, the final output HTML table is missing the chemistry and algebra columns. import pandas as pd df = pd.DataFrame({'name': ['Somu', 'Kiku', 'Amol&ap ...

update content of input field using Python Selenium

Hey, I have a snippet of code that looks like this: <input id="txt_search" class="search-box tp-co-1 tp-pa-rl-5 tp-re tp-bo-bo" type="text" placeholder="Search Stocks" onmouseup="this.select();" autoco ...

Inspecting contents of browser using Python for web scraping

Currently, I am utilizing Python along with Selenium and Chrome web drivers to conduct web scraping within Visual Studio Code. Upon sending a GET request like this: driver.get('https://my_test_website/customerRest/show/?id=123') I am curious ab ...

Guide: Generating a Random Number with Prefix using Python

Can you help me create a list of all potential numbers in the given prefix? import random prefix = "05" print prefix + #List of Potential Numbers Goes Here ...

Tips for navigating directly to the final page of a paginated Flask-Admin view without needing to sort in descending order

In my Python Flask-Admin application for managing database tables, I am looking to have the view automatically start on the last page of the paginated data. It is important to note that I cannot simply sort the records in descending order to achieve this. ...

Generate a personalized report for the Behave Python framework, requiring retrieval of both the Scenario Name and its corresponding status

Looking to generate a personalized report for the Behave and Python framework. The goal is to retrieve the Scenario Name and status. Any suggestions on how to accomplish this? Curious if there is an event listener class available in the behave framework t ...

How to retrieve data from a PL/SQL function using cx_Oracle in Python

I need assistance in running an Oracle PL/SQL statement using cx_oracle in Python. Here is the code snippet: db = cx_Oracle.connect(user, pass, dsn_tns) cursor = db.cursor() ... sel = """ DECLARE c NUMBER := 0.2; mn NUMBER := 1.5; res NUMBER; ...

Divergent Results in Sorting Algorithms Between Python Arrays and Numpy Arrays

Below, you will find some code for a merge sort algorithm that I have implemented. Initially, I tested it using a Python array of integers and everything was working perfectly. However, when I decided to test it further by generating a random set of number ...

Tips for optimizing session.add with various relationships to improve performance

Below is the model structure of my source code, represented as an array in a dictionary format. # data structure user_list = [{user_name: 'A', email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8feeeeeecfe ...

Is there a way to delete the initial page from various PDF documents within a folder using PYTHON?

I am struggling to remove the first page of multiple PDF files in a specific directory. As someone who is new to Python, I have put together this code by borrowing snippets from various sources, but unfortunately, it's not functioning correctly. Is th ...