Using Python, if you could help me with the code
# Create a modified version of the search linear function
defined
# above to return all
# occurrences of the search word in the text
# An occurrence is the index of a word in the text that matches
your given
# search string.
# e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6,
12]
def search_linear_occurrences(xs, target):
""" Find and return a list of the occurrences of the target in
sequence xs """
l = [] # List of occurrences of target in xs
# Code to complete
return l
---------------------------------------------------------------------------------------------------
The code that I have so far
import urllib.request
# Location of book
url =
"http://openbookproject.net/thinkcs/python/english3e/_downloads/alice_in_wonderland.txt"
local_copy = "alice_in_wonderland.txt" # Local file to store book
in
urllib.request.urlretrieve(url, local_copy) # This function
copies the
# thing the url points at into the local file copy
with open(local_copy) as fh: # Read from the local file into a
string
alice_text = fh.read()
print(alice_text[:100]) # Let's check we've got the words
# Make all the alphabet characters lower case
alice_text = alice_text.lower()
alice_words = alice_text.split() # Chop the text up into
individual words
# using the split() method, which breaks the string up at
whitespace
print(alice_words[:100])
print("There are: " + str(len(alice_words)) + " words")
def search_linear(xs, target):
""" Find and return the index of target in sequence xs """
for (i, v) in enumerate(xs): # enumerate is a cool function which
returns for each
# element v in a list a pair (i, v), where i is the index of v in
the list
if v == target:
return i
return -1
search_linear(alice_words, target="hatter") # Search for the word "hatter" in the text"
Code:-
def search_linear_occurrences(xs, target):
l = []
for i in range(len(xs)):
if xs[i] == target:
l.append(i)
return l
Using Python, if you could help me with the code # Create a modified version of...
Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...
Could someone help with this function Python? It involves opening and reading from a text file. Write a function that returns a list k of words that start at word i of the text. def extractWord(text, i=0, k=None)
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...
Sample program run - Needs to be coded in python -Enter the text that you want to search for, Or DONE when finished: valiant paris The valiant Paris seeks for his love. -Enter the text that you want to search for, or DONE when finished: Romeo and Juliet Enter Romeo and Juliet aloft, at the WIndow -- Enter the text that you want to search for, DONE when finished: DONE # copy the following two lines into any # program...
Your task is to process a file containing the text of a book available as a file as follows: A function GetGoing(filename) that will take a file name as a parameter. The function will read the contents of the file into a string. Then it prints the number of characters and the number of words in the file. The function also returns the content of the file as a Python list of words in the text file. A function FindMatches(keywordlist,...
Hi, I need some help finishing the last part of this Python 1 code. The last few functions are incomplete. Thank you. The instructions were: The program has three functions in it. I’ve written all of break_into_list_of_words()--DO NOT CHANGE THIS ONE. All it does is break the very long poem into a list of individual words. Some of what it's doing will not make much sense to you until we get to the strings chapter, and that's fine--that's part of...
In Python How do I make the following function below iterate for 20 years. (1996 to 2016) def getComplaints(year, make, model): url0 = #url url = url0.format(year,make,model) s = requests.get(url).text # this is a CSV string df = pandas.read_csv(StringIO(s)) # use pandas to parse the CSV complaints = df.to_dict('records') # convert to list of dicts return complaints I want to change this function so it is able to search from the year 1996 all the way to 2016 and then...
Can someone fix this python program? I'm trying to do three things: Create a function that takes in a string as a parameter. Then create a dictionary of characters to integers, where the integer represents how many times the number of times the character appears in the word. Create a function that takes two lists as parameters and returns the elements they have in common of the two lists. Ask the user to create a list of numbers and keep...
PYTHON PROGRAMMING: I have this program right now where it allows users to choose from a category(pulling from the file). Then it will print the University or people from that text file. What I want to do next on my code is for users to search for a specific string from that file and it will display both the University and People that have that matching string. It can be the whole word or part of the string from that...