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
bagirrra123 [75]
3 years ago
14

Create a dictionary named letter_counts that contains each letter and the number of times it occurs in string1. Challenge: Lette

rs should not be counted separately as upper-case and lower-case. Intead, all of them should be counted as lower-case.
Computers and Technology
1 answer:
Amanda [17]3 years ago
4 0

Answer:

  1. letter_counts = {}
  2. string1 = "I have a dream"
  3. string1 = string1.lower()
  4. for x in string1:
  5.    if(x == " "):
  6.        continue  
  7.    if x not in letter_counts:
  8.        letter_counts[x] = 1
  9.    else:
  10.        letter_counts[x] += 1
  11. print(letter_counts)

Explanation:

The solution is written in Python 3.

Firstly create a letter_count dictionary (Line 1)

Next, create a sample string and assign it to string1 variable and convert all the characters to lowercase using lower method (Line 4).

Create a for loop to traverse through each character in string1 and check if the current character is a single space, just skip to the next iteration (Line 7 -8). If the current character is not found in letter_counts dictionary, set the initial count value 1 to x property of letter_counts. Otherwise increment the x property value by one (Line 9 -12).

After completion of loop, print the letter_count dictionary. We shall get the sample output {'i': 1, 'h': 1, 'a': 3, 'v': 1, 'e': 2, 'd': 1, 'r': 1, 'm': 1}

You might be interested in
Which element of a presentation program’s interface displays the slide you are currently creating or editing?
irinina [24]

I believe the answer is: Slide Plane

5 0
2 years ago
Read 2 more answers
A. experiment by purposely misconfiguring the gateway address on pc-a to 10.0.0.1. what happens when you try and ping from pc-b
MrRa [10]
Yes you will mate, hope this helps!
7 0
2 years ago
To enforce the concept of separating class definition from its function implementations, where should the function implementatio
zzz [600]
D(in a .c file ) because that is where it should be placed :)
4 0
2 years ago
Analyze the following code:
olganol [36]

Answer:

The program displays 5 4 3 2 1 and then raises an Array Index Out Of Bounds Exception.

Explanation:

A sample of code output is attached.

The code snippet contain xMethod that takes an array and array length as argument.

In the given snippet, the array {1, 2, 3, 4, 5} and length (5) is passed as argument to the method.

First the method display the element of the array in reverse order

System.out.print(" " + x[length - 1]);

and then the method call itself again. This displays

5 from x[4]

4 from x[3]

3 from x[2]

2 from x[1]

1 from x[0]

but after displaying 1, when it tries to call the method again, an array index out of bound exception is thrown because it will try accessing an element from the array when it is already exhausted.

5 0
2 years ago
What is one way to maintain Internet safety? a) avoid interacting with people on the Internet. B) avoid giving out information a
Anarel [89]
To be safe on the Internet, we must avoid giving out personal information.
4 0
3 years ago
Other questions:
  • Carolyn owns a small business that designs air conditioning units for large buildings. A construction company that's building an
    13·1 answer
  • Submit your 300-word essay describing the equipment usedI in a well-equipped studio’s audio department and the training and expe
    8·2 answers
  • Jerry is making an address book using a digital database. He has a list of his immediate family and friends but wants to add a f
    9·2 answers
  • Which option best describes the cheapest way to file your federal income taxes?
    5·1 answer
  • Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method. T
    14·1 answer
  • Answer the following questions: • What is the source of the user’s request? Can a technical solution solve his problem? Perhaps
    10·1 answer
  • How many different textile items would you find at a festival? (please list 5 items)
    7·1 answer
  • Does analogue conversation take place in source as transmitter?
    5·2 answers
  • I WILL MARK BRAINIEST FOR THIS!!!!!!
    11·2 answers
  • Algorithm to eat orange<br><br>​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!