Question

PYTHON please -Create a function that takes a character chain and returns a histogram in a...

PYTHON please

-Create a function that takes a character chain and returns a histogram in a dictionary format.

• The main program must take a dictionary and display it in alphabetical order.

Note d.get(val1, val2) will return the value of the key val1 from dictionary d, otherwise val2. If we try to access directly d[val1], we get an error if key val1 does not exist.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Your problem statement is not very clear, like what should be the histogram made of. Since you have not provided these details, I am providing the code by making some assumptions. In case of any queries, feel free to reach out via comments section.

CODE

def histogram(chain):

all_freq = {}

for i in chain:

   if i in all_freq:

     all_freq[i] += 1

   else:

     all_freq[i] = 1

print("The histogram is: ")

for key in all_freq:

print(str(key) + " ======> ", end = "")

for i in range(all_freq[key]):

print("*", end = "")

print()

histogram("helloworld")

Add a comment
Know the answer?
Add Answer to:
PYTHON please -Create a function that takes a character chain and returns a histogram in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement a Python function called revd that takes a chain of characters and returns a new...

    Implement a Python function called revd that takes a chain of characters and returns a new chain with the double of the elements but in reverse order. In the main program, ask the user to input the chain of characters, call the function and display the result Example : Please enter a chain of characters: abcd ddccbbaa NOTE: This is a repost. Please DO NOT use GLOBAL Variables

  • Create a function that takes a list and an integer v, and returns True if v...

    Create a function that takes a list and an integer v, and returns True if v is in the list (False otherwise). The function should be efficient and stop searching as soon as possible. •The main program must generate a very large list with random elements, call the function to search a value and display the result. Add in the function a variable Nsteps to count the number of steps used by the algorithm (number of times the loop is...

  • Python Language Create a module (1 mark) a) Create a function that takes three (3) arguments...

    Python Language Create a module (1 mark) a) Create a function that takes three (3) arguments (1 mark) i) Name it whatever you’d like (1 mark) ii) It will return a dictionary with the following keys (1 mark) (1) Error => gives error message or empty string if not (1 mark) (2) Result => gives result or empty string if no result (1 mark) b) Ensure that all three arguments are of String (str) datatype (1 mark) i) Return an...

  • PYTHON PROGRAM by using functions & dictionary or set. - must create a variable to hold...

    PYTHON PROGRAM by using functions & dictionary or set. - must create a variable to hold a dictionary or sets - must define a function that accepts dictionaries or sets as an argument A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keys to values. For e.g.: a dictionary defined as: released = { "iphone" : 2007, "iphone 3G": 2008, "iphone 3GS": 2009, "iphone 4" : 2010,...

  • Python: Create a function count_target_in_list that takes a list of integers and the target value then...

    Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...

  • Write a function named "loadStateDict(filename) that takes a filename and returns a dictionary of 2-character state...

    Write a function named "loadStateDict(filename) that takes a filename and returns a dictionary of 2-character state codes and state names. The file has four columns and they are separated by commas. The first column is the state full name and the second column is the state code. You don't have to worry about column 3 & 4. You should eliminate any row that is without a state code. Save the two columns into a dictionary with key = state code...

  • The Asc function in VB takes a character and return an integer that represents that character. It does not matter what the integer representing the character actually is, but what matters is this: Asc...

    The Asc function in VB takes a character and return an integer that represents that character. It does not matter what the integer representing the character actually is, but what matters is this: Asc("a") is 1 less than Asc("b"), so that: x=Asc("a") thisLetter = x+1 # thisLetter is the Asc("b") This is a powerful fact that is used in encryption techniques, so data transferred over the web is 'deciphered so it is unreadable to others. To decipher data, we take...

  • Questions 1. How to create a comment in python? 2. The way to obtain user input...

    Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • Can I see that source code in python Write the following value-returning function: encoded - Takes...

    Can I see that source code in python Write the following value-returning function: encoded - Takes a string as parameter and returns the string with each vowel substituted by its corresponding number as follows: a -1 e-2 0-4 。u_5 The function MUST USE string slicing Write a main program that will take an input string (text) from command line and it will display the input text encoded. You will call the encoded function to get the text encoded.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT