Question

Consider that two strings are perms of one another if the same number of every character...

Consider that two strings are perms of one another if the same number of every character is present in both. Thus the two strings ‘aabcc’ and ‘ccbaa’ are perms, for each has two a’s, one b and 2 c’s. Another example: the strings ‘xyyz’ and ‘yxz’ are not perms, for one has two y’s and the other has only one. Take two lists of strings. Find how many members of the first have a perm in the second using Phyton program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source Code::-

def perms(str1,str2):

#perms() which takes two string as an argument.

if len(str1) == len(str2):

#First will check the length of two string, if length is equal then only will match character

for char in str1:

#Looping one by one character

if (str1.count(char)) != (str2.count(char)):

#If character count is not equal then returns False

return False

return True

else:

return False

if __name__=="__main__":

list1 = ["aabbcc","abc","xyz","pqrst","aabcc"] #Created list1 which has five items

list2 = ["aabbcc","xxyz","cba","pqqrst","ccbaa"] ##Created list2 which has five items

count = 0 #Initalize the count variable

for item1 in list1:

   #looping item from list1

   for item2 in list2:

   #Looping item from list2

   if not(perms(item1,item2)):

#calling perms() method which will find the perms between two words.

#If method is returning False, means that two words are not perms.

pass

   else:

   #If perms() method returns True, means that two words are perms.

   count+=1 #Increament the count variable.

print("No of perms found between two list is::%d"%count)

Output::-

No of perms found between two list is::3

Screen Shot::-

Output screen shot::-

Add a comment
Know the answer?
Add Answer to:
Consider that two strings are perms of one another if the same number of every character...
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
  • In Java Index of Coincidence If two strings of equal length are superimposed on one another,...

    In Java Index of Coincidence If two strings of equal length are superimposed on one another, then some letters may match. For example consider the strings wonderwhowrotethebookonlove and weallliveinayellowsubmarine Notice that there are three positions that contain the same letter: the 1 st (w) , 14 th (e), and 27 th (e). Of 27 possible positions, matches occur in three positions (11.1%). This percentage is called the index of coincidence for two strings, and it is used to decrypt ciphers...

  • Prompt the user to enter two character strings. The program will then create a new string...

    Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...

  • A simple instrument consists of two metal strings stretched parallel to one another and attached at...

    A simple instrument consists of two metal strings stretched parallel to one another and attached at both ends to boards perpendicular to the strings. The tension is the same in both strings, and the length of the strings is ` = 35.0 cm. The first string has a mass m = 8.00 g and generates middle C (frequency f = 262 Hz) when vibrating in its fundamental mode. a) What is the tension in the first string? b) If the...

  • Consider the following C++ program. It reads a sequence of strings from the user and uses...

    Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...

  • Instructions: Consider the following C++ program. It reads a sequence of strings from the user and...

    Instructions: Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common?...

    Consider the two strings "doggie dish" and "Drip coffee". What letters do they have in common? That is, what is the letter intersection count for the pair of strings? Let's look at 'd' first. The first string has 2 d's (d's occurrence count is 2), while the second has just 1 d (capitalization doesn't count) - so the intersection for the strings for d is 1. What about g? There the occurrence counts are 2 and 0, so the intersection...

  • Imagine we are using a two-dimensional array as the basis for creating the game battleship. In...

    Imagine we are using a two-dimensional array as the basis for creating the game battleship. In the game of battleship a '~' character entry in the array represents ocean, a '#' character represents a place ion the ocean where part of a ship is present, and an 'H' character represents a place in the ocean where part of a ship is present and has been hit by a torpedo. Thus, a ship with all 'H' characters means the ship has...

  • Please note that I cannot use the string library function and that it must be coded...

    Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

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