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
ozzi
3 years ago
13

Def build_dictionary(string):

Computers and Technology
1 answer:
MissTica3 years ago
4 0

Answer:

Follows are the code to this question:

def build_word_counter(string):#defining a method build_word_counter that accepts string as a parameter  

   d = dict()#defining d variable as a dictionary

   for x in string:#defining for loop that use string

       x = x.lower()#Use lower method  

       if not d.get(x):#defining if block that holds value in d variable

           d[x] = 1#use dictionary to hold value in 1

       else:#defining else block

           d[x] += 1#use dictionary to increment value by 1

   return d#return dictionary

print(build_word_counter(["Like","like","LIKE"]))#use print method to call method

def build_letter_distribution(string):#defining a method build_letter_distribution that accepts string variable

   d = dict()#defining d variable as a dictionary

   for i in string:#defining for loop to count string value

       for j in i:#defining for loop to hold string as number

           if not d.get(j):#defining if block that doesn't get value in dictionary  

               d[j] = 1#hold value in dictionary  

           else:#defining else block

               d[j] += 1#use dictionary to increment the dictionary value

   return d#return dictionary

print(build_letter_distribution(["Like","test","abcdEFG"]))#use print method to return its value

Output:

please find the attached file.

Explanation:

In the first program a method, "build_word_counter" is defined that accepts a string variable in its parameter, and inside the method, a dictionary variable "d" is defined that uses the for loop to hold string value and convert all value into lower case.

In the next step, a conditional statement is used that holds value in the dictionary and count its word value.

In the second program a method, "build_letter_distribution" is defined that holds string variable in its parameter, and inside the method, a dictionary variable "d" is defined that uses the two for loop and in if the block, it holds value in the dictionary and returns its value, and use print method to print its return its value.

You might be interested in
What is qwerty and why is it on the keyboard?
Genrish500 [490]

Answer:

qwerty is the main way people sort out there keyboard as you can see on the left side of the keyboard there is W,A,S,D

Explanation:

6 0
4 years ago
Read 2 more answers
Stanovte intenzitu magnetického poľa v strede tenkej cievky s 20 závitmi. Prúd je 2A , stredný polomer cievky je 4cm.
ExtremeBDS [4]

Answer:

Determine the intensity of the magnetic field in the center of a thin coil with 20 turns. The current is 2A, the mean radius of the coil is 4cm.

Explanation:

to help english help you

4 0
3 years ago
Classify the characteristics as abstract classes or interfaces.
Sergeu [11.5K]
E for eeeedeerreeeee
4 0
3 years ago
The sun produces energy by the process of nuclear: <br><br> A.fission <br> B.fusion
ELEN [110]
Fission because fission puts them together
3 0
3 years ago
Read 2 more answers
Who was the first president
Firlakuza [10]
George Washington was the first president of the United States that is your answer
4 0
3 years ago
Read 2 more answers
Other questions:
  • Households pay taxes to the government and receive public services. Which of the following is a public service?
    8·1 answer
  • Database designers typically do not add spaces in field names (LName), but can add details in the ________ field of the field pr
    12·1 answer
  • How would a top margin be set
    7·1 answer
  • Calculate the average of a set of grades and count
    9·1 answer
  • A magnetic disk drive requires a motor to position a read/write head over tracks of data on a spinning disk, (see fig. e4.4 in d
    8·1 answer
  • Help! Computer Science Discoveries. Hurry its timed
    15·1 answer
  • Which set of symbols encloses an if-then code block? Choose the best answer.
    10·1 answer
  • 100 POINTS!! Help me out please I need help with this!!
    12·1 answer
  • Select three advantages of cloud computing.
    12·1 answer
  • Who tryna trade in gta my psn is xMadOrNawx-_-
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!