Question
MAKE SURE OUTPUT 4 IS CORRECT - Python
PROBLEM: A useful computer utility is to report the differences between two files. In this program, you will compare two stri
The quick brown fox did jump over a log The brown rabbit quickly did out jump the fox How many pickled peppers did Peter Pipe
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program

#Method to find common string
#Pass two strings as arguments
#Print commonstring if present
#Otherwise NONE
def CommonDifference(A,B):
    #Check empty string
    if len(A)==0 or len(B)==0:
        print("NONE")
    #Otherwise
    else:
        #Generate lists of the strings
        lstA=A.split()
        lstB=B.split()
        #List for comparison storage
        firstComp=[]
        secondComp=[]
        commStr=[]
        #Loop to find A to B comaprarison
        for i in range(0,len(lstA)):
            index=B.find(lstA[i])
            if(index>=0):
                firstComp.append(lstA[i])
                firstComp.append(" ")
        #Loop to find B to A comaprarison
        for i in range(0,len(lstB)):
            index=A.find(lstB[i])
            if(index>=0):
                secondComp.append(lstB[i])
                secondComp.append(" ")
    #Generate strings
    firstComp="".join(firstComp)
    secondComp="".join(secondComp)
    #Second algorithm loop
    for i in range(0,len(firstComp)):
        #Find index of character match
        index=secondComp.find(firstComp[i])
        #Check the found index not space
        if(index>=0 and firstComp[i]!=' '):
            #Add into comparison list
            commStr.append(firstComp[i])
            #Remove charcters including inex
            secondComp=secondComp[index+1:]
    #Generate common string
    commStr="".join(commStr)
    #Check empty or not
    #Then print corresponding result
    if(len(commStr)>0):
        print(commStr)
    else:
        print("NONE")
#Main
def main():
    #Check
    CommonDifference("The quick brown fox did jump over a log","The brown rabbit quickly did outjump the fox")
#Call main
main()

---------------------------------------------------------

Output

Theiox

----------------------------------------------

Add a comment
Know the answer?
Add Answer to:
MAKE SURE OUTPUT 4 IS CORRECT - Python PROBLEM: A useful computer utility is to report...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Recursion and Trees Application – Building a Word Index Make sure you have read and understood...

    Recursion and Trees Application – Building a Word Index Make sure you have read and understood ·         lesson modules week 10 and 11 ·         chapters 9 and 10 of our text ·         module - Lab Homework Requirements before submitting this assignment. Hand in only one program, please. Background: In many applications, the composition of a collection of data items changes over time. Not only are new data items added and existing ones removed, but data items may be duplicated. A list data structure...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT