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
Briefly explain what is net neutrality and why is it important today
ICE Princess25 [194]

Net neutrality also means that ISPs can't charge users access fees for particular websites. ... The goal of net neutrality is to ensure that businesses can compete freely on the internet without having to pay gatekeeper tolls. Without it consumers would look more like advertising segments than an open marketplace.

Credits: thestreet.com

6 0
3 years ago
Who want followers on Instagram... gotta follow back
Alexxx [7]

Explanation:

I dont have Instagram....

6 0
3 years ago
Read 2 more answers
Major findings of evolution of computers
Elis [28]

Answer:

twitt

Explanation:

3 0
3 years ago
Please help me, I honestly dont know what happened to my laptop.
Alex787 [66]
Restart the whole computer??
7 0
3 years ago
Read 2 more answers
Microsoft word's spelling checker will offer suggestions on misspelled words.<br> True)<br> False)
Rasek [7]
This is true. I hope I was helpful!
7 0
3 years ago
Read 2 more answers
Other questions:
  • When it comes to saving money, what is a good rule of thumb?
    5·2 answers
  • An ink-jet printer is a type of impact printer. <br> a. True <br> b. False
    8·1 answer
  • Find the reciprocal of 7/2 × 3/5<br>​
    6·1 answer
  • Use a switch statement to display "one" if the user has entered 1, "two" if the user has entered 2, and "three" if the user has
    14·1 answer
  • E-mail has made it very easy to send a message to more than one person at any time of day from just about anywhere. If you wante
    7·1 answer
  • CLICK ME IF U DARE hehehe
    10·2 answers
  • Pls help I will give points
    7·1 answer
  • Question # 6
    11·2 answers
  • When you start a new blank document, you begin typing at the
    6·1 answer
  • Refund please, this has not helped at all.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!