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
Lesechka [4]
3 years ago
14

1. Please write the following code in Python 3.2. Please also show all outputs.Create a dictionary named letter_counts that cont

ains each letter and the number of times it occurs in string1. Challenge: Letters should not be counted separately as upper-case and lower-case. Intead, all of them should be counted as lower-case.string1 = "There is a tide in the affairs of men, Which taken at the flood, leads on to fortune. Omitted, all the voyage of their life is bound in shallows and in miseries. On such a full sea are we now afloat. And we must take the current when it serves, or lose our ventures."
Computers and Technology
1 answer:
nevsk [136]3 years ago
4 0

Answer:

string1="There is a tide in the affairs of men, Which taken at the flood, leads on to fortune. Omitted, all the voyage of their life is bound in shallows and in miseries. On such a full sea are we now afloat. And we must take the current when it serves, or lose our ventures."

string1=string1.lower()   #covert whole string to lowercase

letter_counts={}

for ch in string1:

   letter_counts[ch]=letter_counts.get(ch,0)+1   #updates counter for each letter

letter_counts['o']

OUTPUT :

17

Explanation:

lower() is used to change the string to lowercase characters so that uppercase and lowercase is not differentiated for the same letter. After that, letter_counts is declared as a dictionary which is empty. for loop is used in which every letter of string will be stored ch variable. Dictionary in python has a get method in which 2 arguments can be passed, first one is the key whose value to be retrieved and the other argument would be default value to be set if not found and ch in string1 will increment the value of key ch in letter_counts.

You might be interested in
As you are planning your informative speech on the prevalence of Internet memes in pop culture and you wonder if your audience w
Tasya [4]

Answer:

i dont get it

Explanation:

what is the question?

4 0
3 years ago
What is the difference between margin and padding property?
VMariaS [17]

Answer:

Margin is applied to the outside of your element hence affecting how far your element is away from other elements.

Padding is applied to the inside of your element hence affecting how far your element's content is away from the border.

Explanation:

Hope it helps!!!

6 0
2 years ago
I need the answers. i don’t get this
bixtya [17]
Run,lazy,turtles,slow,wandering, jump,45,weird,pigs, cows, cousins, pale,rude,candles

There are many answers for this but this is what first came to my mind

Hope this helps
4 0
3 years ago
What is the simplest way to permanently get rid of an unwanted file on the computer
Mrac [35]
Delete it. Also defragmentation may be an option if your computer is running slow.
8 0
4 years ago
There is an increasing need for private security personnel because of declining resources for many government agencies and a sho
aivan3 [116]
<span>True
</span><span>There is an increasing need for private security personnel because of declining resources for many government agencies and a shortage of police officers in many communities due to lack of funding.

</span>
8 0
4 years ago
Other questions:
  • What's does the Mutual Reward Theory state?
    10·1 answer
  • Electronic files created on a computer using programs such as word software are considered to be
    15·1 answer
  • In a database list, fields are displayed as _____. rows columns tables records
    10·1 answer
  • The engine flywheel bolts to the Rotor Pistons Front axle Crankshaft
    13·1 answer
  • When creating a shape in Word, what are some available options? Check all that apply. adding text to the shape changing the size
    6·1 answer
  • Assignment 4: Evens and Odds
    9·1 answer
  • A Development team begins work on a new software application and decides to involve the client’s IT experts to ensure that secur
    12·1 answer
  • What is a saved link to a particular web page?​
    7·1 answer
  • Write a program that prompts the user for two numbers then outputs the result of dividing the first number by the second number
    10·1 answer
  • Show the B-tree that results when inserting R,Y,F,X,A,M,C,D,E,T,H,V,L,W,G (in that order)branching factor oft= 3. You need only
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!