Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Please explain this Python code
def trigrams(ls,t): # counts user supplied trigram
trioccurs = 0
# loop through longstring counting occurences of target
for lc in range(0,len(ls)-2):
if ls[lc:lc+3] == t:
trioccurs += 1
return trioccurs
def trigrams(ls): # uses a dictionary; finds all trigrams
dict = {}
# loop through longstring counting occurences of target
for lc in range(0,len(ls)-2):
t = ls[lc:lc+3]
# if not there, insert into dictionary
if t not in dict:
dict[t] = 1
else:
dict[t] = dict[t] + 1
return dict
trioccurs = 0
# loop through longstring counting occurences of target
for lc in range(0,len(ls)-2):
if ls[lc:lc+3] == t:
trioccurs += 1
return trioccurs
def trigrams(ls): # uses a dictionary; finds all trigrams
dict = {}
# loop through longstring counting occurences of target
for lc in range(0,len(ls)-2):
t = ls[lc:lc+3]
# if not there, insert into dictionary
if t not in dict:
dict[t] = 1
else:
dict[t] = dict[t] + 1
return dict
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- get_top_regions() that takes three input parameters; the 2-D list (similar to the database), the dictionary that stores information of all regions, and a non-zero positive integer x. This function returns a new dictionary that contains the information of top-x regions in terms of the total number of hospitalization cases recorded in these regions. That means these top-x regions have the largest numbers of hospitalization cases. Each {key:value} pair in this resulting dictionary stores the name of a top region as the key and the value is the total number of hospitalization cases reported in this region. The result does not need to be sorted, the regions of the resulting dictionary can appear in any order as long as the top-x regions have been identified correctly. If the value of x is less than 1, or more than the total number of unique regions, your function should print a message informing the user and return an empty dictionary. See sample outputs below. >>> topx_regions…arrow_forwardIntSet unionWith(const IntSet& otherIntSet) const; //Unions the current set with the passed set. IntSet::unionWith(const IntSet& otherIntSet){ for (int i = 0; i < otherIntSet.used; ++i) //For each element in the passed set. { add(otherIntSet.data[i]); //Add it to current set. }}arrow_forwardPython question, need some helparrow_forward
- A date-to-event dictionary is a dictionary in which the keys are dates (as strings in the format 'YYYY-MM-DD'), and the values are lists of events that take place on that day. Complete the following function according to its docstring. Your code must not mutate the parameter! def group_by_year (events: Dict[str, List[str]]) -> Dict [str, Dict [str, List[str]]]: """Return a dictionary in which in the keys are the years that appear in the dates in events, and the values are the date-to-event dictionaries for all dates in that year. >>> date_to_event = {'2018-01-17': ['meeting', 'lunch'], '2018-03-15': ['lecture'], '2017-05-04': ['gym', 'dinner']} >>> group_by_year (date_to_event) {'2018': {'2018-01-17': ['meeting', 'lunch'], '2018-03-15': ['lecture']}, '2017': {'2017-05-04': ['gym', 'dinner']} } || || ||arrow_forwardstruct insert_at_back_of_sll { // Function takes a constant Book as a parameter, inserts that book at the // back of a singly linked list, and returns nothing. void operator()(const Book& book) { /// TO-DO (3) /// // Write the lines of code to insert "book" at the back of "my_sll". Since // the SLL has no size() function and no tail pointer, you must walk the // list looking for the last node. // // HINT: Do not attempt to insert after "my_sll.end()". // ///// END-T0-DO (3) ||||// } std::forward_list& my_sll; };arrow_forwardPythonarrow_forward
- Data Structure & Algorithm: Describe and show by fully java coded example how a hash table works. You should test this with various array sizes and run it several times and record the execution times. At least four array sizes are recommended. 10, 15, 20, 25. It is recommended you write the classes and then demonstrate/test them using another classarrow_forwardq2arrow_forwardPlease complete on Python Write a program that keeps a dictionary in which both keys and values are strings, names of students and their courses grades. Prompt the user of the program to add or remove students, to modify grades, or to print all grades. The printout should be sorted by name and formatted like this: <br>Carl: B+ <br>Joe: C <br>Sarah: A <br>Francine: Aarrow_forward
- Student* func () { unique ptr arr[] make_unique ("CSC340") }; // #1 Insert Code int main () ( // #2 Insert Code [ #1 Insert Code]: Write code to keep all the object(s) which element(s) of array arr owns alive outside of the scope of func. [#2 Insert Code]: Write code to have a weak_ptr monitor the object which survived; Then test if it has any owner; Then properly destroy it; Then test again if has any owner; Then destroy the Control Block.arrow_forwardIn python make a function with the parameter of a dict[str, str] the function will simply invert the dictionary do not use .get, .item, .values, or import builtins If you encounter more than one of the same key when trying to invert the key and value, raise a keyerror for example ['john': 'white', 'garcia': 'white'], should trigger the raise KeyError callarrow_forward12 Language Pythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education