Question

In: Computer Science

Let us define the overlap between two words as the count ofunique letters they have...

Let us define the overlap between two words as the count of unique letters they have in common. Thus, the overlap between JANE and MICK is 0. Here are some more examples: - The overlap between JANE and MIKE is 1 (E is common) - The overlap between JANE and MEEK is 1 (E is common; we do not double count a letter) - The overlap between JANE and JEDI is 2 (J and E are common) - The overlap between JANE and PANEL is 3 (A, N, and E are common) - The overlap between JANE and ANKLE is 3 ( A, N, and E are common) - The overlap between JANE and JAUNDICE is 4 (J, A, N, and E are common) Let us define the total overlap between a word W and a collection of words L as the sum of the overlap between W and each of the words contained in L. Thus the total overlap between the word JANE and the collection of words: [MIKE, MEEK, JEDI, PANEL, ANKLE, JAUNDICE] = 1+1+2+3+3+4 = 14 For Project 5, you will be provided with a collection of 5,163 names (in all caps) inside a text file. Each line in the text file contains a single name. Write a program that finds the total overlap between your first name (in all caps) and this collection. If you are on Windows, the text file you should use is “names_win.txt”. If you are using a Mac to write your programs, the text file to use is “names_mac.txt”. Python solution

Solutions

Expert Solution

Code screenshot :

Sample input :

Sample output:

Copyable code:


input_filename = input("Enter the name of the input file: ")
f1=open(input_filename)#opening the input file

word=f1.readline().strip()#reading the first line which is our word
  
c=0
for line in f1: #reading contents of file
line=line.strip()#to remove leading spaces
word1=word
#code to check overlap characters in the strings
for i in word1:
for k in line:
if (i==k):
c=c+1 #counting the total number of overlaps
k='*' #to avoid duplication check
i='*' #to avoid duplication check
print("The Total number of overlaps for string "+word+" with other words in file are: "+str(c))#printing the output


Related Solutions

Illustrate the orbital overlap between the bonding electrons in water. Which two orbitals overlap when a...
Illustrate the orbital overlap between the bonding electrons in water. Which two orbitals overlap when a chlorine atom and an iodine atom overlap to form a covalent bond? Draw an illustration of the orbital overlap. Are the bonding electrons shared equally between the two atoms? Explain your reasoning.
Machine Learning - multivariate methods Let us say in two dimensions, we have two classes with...
Machine Learning - multivariate methods Let us say in two dimensions, we have two classes with exactly the same mean. What type of boundaries can be defined? show a picture of the options
Let us define "peak oil" as a point in time where the quantity of oil extracted...
Let us define "peak oil" as a point in time where the quantity of oil extracted and consumed (let's just assume these are the same) reaches a maximum and then starts to decline. Based on economic theory, (in other words, I'm not asking you to predict anything specific about the oil market in the real world, just a general theory question) should we expect this period of declining production to be accompanied by high and rising prices or by low/falling...
two words that end in the same portion of letters but sound different are said to eye rhyme.
two words that end in the same portion of letters but sound different are said to eye rhyme. write a python program that prompts the user for an input and prints all the words that eye rhyme with the input, words with the same last three letters, use dictionary file
Let us assume that there are two visitors, A and B, in an amusement park. The...
Let us assume that there are two visitors, A and B, in an amusement park. The demand curve for the visitors facing the amusement park are as follows. PA= 5 – 2QA PB= 2.5 – 0.5QB Marginal cost (MC) to serve each visitor is equal to $1. a. If the amusement park decides to set the price using two-part tariff, given the demand curve P=6 – 2.5Q and MC =$1, how much is the equilibrium P and Q b. Calculate...
Define optimism bias and overconfidence bias in finance. What is the difference between the two? Have...
Define optimism bias and overconfidence bias in finance. What is the difference between the two? Have you ever encountered these cognitive biases from your personal finance experience or work experience? Can you share with us?
Assume two firms have little geographic overlap in terms of sales and facilities. If they were...
Assume two firms have little geographic overlap in terms of sales and facilities. If they were to merge, how might this affect the potential for synergy?
A couple is planning to have a family. Let us assume that the probability of having...
A couple is planning to have a family. Let us assume that the probability of having a girl is 0.48 and a boy is 0.52, and that the gender of this couple’s children are pairwise independent. They want to have at least one girl and at least one boy. At the same time, they know that raising too many kids is difficult. So here’s what they plan to do: they’ll keep trying to have children until they have at least...
Let u and v be two integers and let us assume u^2 + uv +v^2 is...
Let u and v be two integers and let us assume u^2 + uv +v^2 is divisible by 9. Show that then u and v are divisible by 3. (please do this by contrapositive).
in JAVA, Hash table The goal is to count the number of common elements between two...
in JAVA, Hash table The goal is to count the number of common elements between two sets. Download the following data sets, and add them to your project: girlNames2016.txt boyNames2016.txt These files contain lists of the 1,000 most popular boy and girl names in the US for 2016, as compiled by the Social Security Administration. Each line of the file consists of a first name, and the number of registered births that year using that name. Your task is to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT