1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksklad [387]
3 years ago
5

An anagram of a string is another string with the same characters in the same frequency, in any order. For example 'ab', 'bca, a

cb), 'bac', 'cba, 'cab' are all anagrams of the string 'abc'. Given two arrays of strings, for every string in one list, determine how many anagrams of it are in the other list. Write a function that receives dictionary and query, two string arrays. It should return an array of integers where each element i contains the number of anagrams of queryll that exist in dictionary.
Computers and Technology
1 answer:
nlexa [21]3 years ago
4 0

Answer:

from collections import Counter

def anagram(dictionary, query):

   newList =[]

   for element in dictionary:          

       for item in query:

           word = 0

           count = 0

           for i in [x for x in item]:

               if i in element:

                   count += 1

                   if count == len(item):

                       newList.append(item)

   ans = list()

   for point in Counter(newList).items():

       ans.append(point)

   print(ans)        

mylist = ['jack', 'run', 'contain', 'reserve','hack','mack', 'cantoneese', 'nurse']

setter = ['ack', 'nur', 'can', 'con', 'reeve', 'serve']

anagram(mylist, setter)

Explanation:

The Counter class is used to create a dictionary that counts the number of anagrams in the created list 'newList' and then the counter is looped through to append the items (tuple of key and value pairs) to the 'ans' list which is printed as output.

You might be interested in
¿Cuál es el objetivo principal de los servicios?
sleet_krkn [62]
Ayudar a las personas que los contratan
8 0
3 years ago
Arrays are described as immutable because they are two dimensional. are arranged sequentially. can be reordered. cannot be chang
Vlada [557]

Answer:

Arrays are described as immutable because they cannot be changed once they are defined.  (D on Edge)

Explanation:

It's in the notes and I just took the test (2020)

6 0
3 years ago
The ____ command creates a subdirectory under a directory. rd md cd ad
katovenus [111]
Md command, (make directory) creates a directory. It's a subdirectory when you md under a directory.
5 0
3 years ago
1. What conversion factor should be used to convert from Gigaliters to liters?
Ilia_Sergeevich [38]
The conversion factor is 10 to the 9th power
5 0
3 years ago
Supervisor: You will need to consolidate your trouble tickets
liubo4ka [24]
Wheres the rest???????????????????
7 0
3 years ago
Other questions:
  • Behaving in an acceptable manner in a workplace environment is referred to as workplace etiquette.
    12·2 answers
  • Write a program that uses for loops to perform the following steps: Prompt the user to input two integers: firstNum and secondNu
    15·1 answer
  • Write a Program in C language using arrays:
    14·1 answer
  • Which component of a word processor displays the name of the document?
    13·1 answer
  • Explain why it is important to follow a course or a program in keeping with your value system​
    13·1 answer
  • Drag the right word to it’s definition
    13·1 answer
  • What is the function of a breadcrumb trail in a website?
    13·1 answer
  • How do i stop my computer from automatically connecting to a wireless network
    5·1 answer
  • SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SUSSY SU
    6·2 answers
  • Where to store <br> ammunition
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!