Question

python

I this question, you will be given a list of integers, and you have to 
write in a text file named "question3.txt" a barplot corresponding to the 
given numbers, as shown below. For example, if you are given [3,5,2,6,4], 
then you will write in the file the following plot:

----- question3.txt -----
      |
  |   |
  |   | |
| |   | |
| | | | |
| | | | |
3 5 2 6 4
-------------------------

The given integers will be between 0 and 9 (both inclusive). 
"""

def file_plot(l1):
    return # Remove this line to answer this question


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

program

import os
from os import path

def text2dict(filename):
data_dict={}
if path.exists(filename):
f = open(filename, "r")
data=f.read()
print(data)
for i in data:
if i!='\n':
if i in data_dict:
data_dict[i]=data_dict[i]+1
else:
data_dict[i]=1
  
  
return data_dict

  
filename="C:/Users/user/IR_WORK/text.txt"
dict=text2dict(filename)
print(dict)

output

runfile('C:/Users/user/IR_WORK/chegg.py', wdir='C:/Users/user/IR_WORK')
hello
name
{'h': 1, 'e': 2, 'l': 2, 'o': 1, 'n': 1, 'a': 1, 'm': 1}

C:\Users\user\IR_WORK Е, 2 ас chegg.py X Name Type Size Value dict dict 7 {h:1, e:2, l:2, o:1, n:1, a:1, m:1} f


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
python
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
  • python

    Write a function that reads a single line of numbers from a file named  "question1.txt", and returns the average of the numbers read. For example, if  the file is as follows: ----- question1.txt ----- 1 3 5 -2 4 0 6 -2 -3 ------------------------- then the function must return 12/9 = 1.33333 """ def file_average():     return # Remove this line to answer this question

  • python

    Write a function that takes two lists of integers X and Y as input, and  computes and writes a table into a file named "question2.txt" as follows: - On each line the computations for an X,Y pair is given  - Each such possible pair must exist in the file in the same order of values in X and Y - Next on each line, you provide X+Y, X*Y and X^2 + Y^2, all separated by a  comma (and no spaces or other characters must exist). Note that X^2 represents  "square of X".  For example, given X = [1,3] and Y=[-1,1,0], "question2.txt" should contain the following table: ----- question2.txt ----- 1,-1,0,-1,2 1,1,2,1,2 1,0,1,0,1 3,-1,2,-3,10 3,1,4,3,10 3,0,3,0,9 ------------------------- As you can see, the first line is computed for X=1, Y=-1. The second line is  built for X=1, Y=1; and the third line is for X=1, Y=0. It goes on like this,  until X=3, Y=0.  """ def op2file(X, Y):     return # Remove this line to answer this question

  • python

    Complete the below function that takes a file name and a list as arguments and reads the text within the corresponding file, then creates a dictionary whose keys are the characters of the provided list, and the values are the counts of these characters within the text. If a character in the list is not included in  the text, "0" should be written in the dictionary as the value of this  character. The function returns the created dictionary as a result. If the file  does not exist, then the function returns an empty dictionary. Here is an example case, assuming a file named "sample.txt" exists with the  following content: ----- sample.txt ----- This is an example sentence. This is yet another sentence. ------------------------- >>> text2dict("sample.txt", ['a', 'b', 'c', 't']) {'a':3, 'b':0, 'c':2, 't':4} """ def text2dict(filename, characters):     return # Remove this line to answer this question

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • *PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code...

    *PYTHON EXPERTS ONLY PLEASE* Please provide the answer coded in Python using comments to explain code function. Good answers will be rated with thumbs up! Please answer both parts. Thank you for your time. Question 3 - Suppose you have a file named numbers.csv which contains a bunch of integers, five per line of text, separated by commas. Write code below that will open the _le, read the numbers from it, and print the sum of all the even numbers...

  • python

    pythonComplete the below function that takes the name of two files, inFilename andoutFilename as arguments and reads the text from the inFilename. In this fileeach line contains the Turkish Republic Identity Number (TCNO), name, surnameand telephone number of a person. Your function should sort all personsaccording to their TCNO, write the sorted data into outFilename. If the fileinFilename does not exist, then the function must create an empty file namedoutFilename.For example, if the function is called such asreadText("in.txt", "out.txt")and in.txt...

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line)....

    In python Attached is a file called sequences.txt, it contains 3 sequences (one sequence per line). Also attached is a file called AccessionNumbers.txt. Write a program that reads in those files and produces 3 separate FATSA files. Each accession number in the AccessionNumbers.txt file corresponds to a sequence in the sequences.txt file. Remember a FASTA formatted sequence looks like this: >ABCD1234 ATGCTTTACGTCTACTGTCGTATGCTTTACGTCTACTGACTGTCGTATGCTTACGTCTACTGTCG The file name should match the accession numbers, so for 1st one it should be called ABCD1234.txt. Note:...

  • 1. use python List to Dictionary Write a function that has three parameters: a list of...

    1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...

  • In Python Provide me with your code file, output file and the text file Create a...

    In Python Provide me with your code file, output file and the text file Create a file having different integers than the first one. Save it as numbers1. txt . Write a program that reads all the number and calculates their average. Important: The two files that you are creating will contain different numbers.

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