Question

In: Computer Science

Two words form a "metathesis pair" if you can transform one into the other by swapping...

Two words form a "metathesis pair" if you can transform one into the other by swapping two letters; for example, "converse" and "conserve". Write a function metathesis(word1, word2) to check if the two words can form a metathesis pair. The function will return a Boolean value (True or False). python code without using Zip method

Solutions

Expert Solution

PYTHON CODE

#metathesis() function is used to check whether two words form metathesis pair or not.
#If one word transform into another word by swapping two letters, then return True
#Otherwise return False
#True denotes that two words forms metathesis pair
#False denotes that two words doesn't form metathesis pair
def metathesis(word1, word2):
    letterWord1 = []
    letterWord2 = []
    if len(word1) == len(word2): #Length of string should be same.
        lengthOfString = len(word1)
        for i in range(lengthOfString):
            if word1[i]!=word2[i]:
                letterWord1.append(word1[i])
                letterWord2.append(word2[i])
    if len(letterWord1) == 2 and len(letterWord2)==2 and sorted(letterWord1) == sorted(letterWord2):
        return True
    return False

word1 = input("Enter first word:")
word2 = input("Enter second word:")
print(metathesis(word1, word2))

PYTHON CODE IM,AGE

OUTPUT IMAGE


Related Solutions

You are considering two mutually exclusive (you can do one or the other – not both)...
You are considering two mutually exclusive (you can do one or the other – not both) projects with the following cash flows. Using NPV and IRR, which project should you accept if the discount rate is 5 percent? What if the discount rate is 10 percent? Year Project A Project B 0 -$200,000 -$200,000 1 100,000 0 2 100,000 0 3 100,000 300,000
How do you transform from first normal form to second normal form?
How do you transform from first normal form to second normal form?
Roll a pair of dice (one is red and the other is green). Let A be...
Roll a pair of dice (one is red and the other is green). Let A be the event that the red die is 4 or 5. Let B be the event that the green die is 1 Let C be the event that the dice sum is 7 or 8. Calculate P(A), P(B), P(C) Calculate P(A|C), P(A|B) Are the events A and C independent? Suppose box 1 has four black marbles and two white marbles, and box 2 has two...
Suppose you have a pair of tetrahedra. One is red on one face, yellow on two...
Suppose you have a pair of tetrahedra. One is red on one face, yellow on two faces, and green on one face. The other is white and has faces marked 1, 2, 3 ,4 a. Complete the table 1 2 3 4 Red Yellow Yellow Green b. If both tetrahedra are tossed, what is the probability of a red (facing down) and a 3 (facing down)? Of a yellow (facing down) and a number >1 on the other (facing down?)...
Two curve plastic rods , one of charge +q and the other of charge -q, form...
Two curve plastic rods , one of charge +q and the other of charge -q, form a circle of radius R = 0.50 cm in an xy plane. The x axis passes through both of the connecting points, and the charge is distributed uniformly on both rods. If q = 15.0 pC, what are the (a) magnitude and (b) direction (relative to the positive direction of the x axis) of the electric field produced at P, center of the circle....
2. Describe two exercises and one other strategy (not exercise) that you can undertake to reduce...
2. Describe two exercises and one other strategy (not exercise) that you can undertake to reduce the risk of injury when using a computer. Explain how often you would recommend the exercises are done
Suppose you want to form words with 3 letters and all letters in the alphabet can...
Suppose you want to form words with 3 letters and all letters in the alphabet can be used except A and B (so, XYZ would be a word for example even though it does not make sense). a) How many possibilities do you have if repetition is permitted and ordering is relevant, how many possibilities do you have if repetition is not permitted and ordering is relevant; how many possibilities do you have if repetition is not permitted and ordering...
Problem 2: Two words are said to be anagrams if one can be formed by permuting...
Problem 2: Two words are said to be anagrams if one can be formed by permuting the letters of the other. For example: "pots", and "stop" are anagrams. An anagram chain is a list of words that are all anagrams to each other. The shortest anagram chain has length two. We are interested in calculating the length of the longest anagram chain in a given list of words. For example, the following nine words: rates, pots, tops, along, aster, stop,...
You have two coins, one of which you know to be fair and the other of...
You have two coins, one of which you know to be fair and the other of which has a probability of turning up heads of 0.7, but you can’t tell which one is which. You choose one coin at random and flip it ten times getting an equal number of heads and tails. What is the probability that you chose the unfair coin?
A specially made pair of dice has only one- and two-spots on the faces. One of...
A specially made pair of dice has only one- and two-spots on the faces. One of the dice has three faces with a one-spot and three faces with a two-spot. The other die has two faces with a one-spot and four faces with a two-spot. One of the dice is selected at random and then rolled six times. If a one-spot shows up only once, what is the probability that it is the die with the three one-spots?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT