Question

In: Computer Science

in PYTHON given a specific text file containing a list of numbers on each line (numbers...

in PYTHON

given a specific text file containing a list of numbers on each line (numbers on each line are different)

write results to a new file after the following tasks are performed:

Get rid of each line of numbers that is not 8 characters long

Get rid of lines that don't begin with (478, 932, 188, 642, 093)

Solutions

Expert Solution

Open Python IDLE and paste the code given below

Change the path given in project for infile and outFile

-------------------------------------------------------------------------------------------------------------------

def main():
#read file from path
infile = open("C:\\Users\\PhoenixZone\\Desktop\\testfile.txt","r")
lines_list = infile.readlines()
infile.close()
#file to write the data
outFile = open("C:\\Users\\PhoenixZone\\Desktop\\outfile.txt","w+")
for line in lines_list:
#Get rid of each line of numbers that is not 8 characters long
if len(line)>8:
#Get rid of lines that don't begin with (478, 932, 188, 642, 093)
if line.startswith('478') or line.startswith('932') or line.startswith('188') or line.startswith('642') or line.startswith('093'):
#write line to output.txt
outFile.write(line)
  
main()

------------------------------------------------------------------------------------------------------

//testfile.txt

478 23 5 5 6
932 5 2 56
6 5 5
985 654 689
093 365 689 12 1
188 2 36 5 6 5 6

--------------------------------------------------------

//output.txt

478 23 5 5 6
932 5 2 56
093 365 689 12 1
188 2 36 5 6 5 6

-------------------------------------------------------


Related Solutions

Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." In C, Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume the length...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C language to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters....
This is a python file Reads information from a text file into a list of sublists....
This is a python file Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster will be a list of sublists, where each sublist...
Language C: Suppose you are given a file containing a list of names and phone numbers...
Language C: Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
/** * Loads a list of items from the given file. Each line is in the...
/** * Loads a list of items from the given file. Each line is in the format * <item type>~<item data>. The createFromString() methods in the item * classes will be used to parse the item data. * @param filename the filename * @return the list of items * @throws IOException if the file can't be opened */ public static List<Item> loadItems(String filename) throws IOException { List<Item> items = new ArrayList<>(); Scanner inPut = new Scanner(new FileReader(filename));        while(inPut.hasNextLine())...
IN PYTHON File Data --- In file1.txt add the following numbers, each on its own line...
IN PYTHON File Data --- In file1.txt add the following numbers, each on its own line (20, 30, 40, 50, 60). Do not add data to file2.txt. Write a program. Create a new .py file that reads in the data from file1 and adds all together. Then output the sum to file2.txt. Add your name to the first line in file2.txt (see sample output) Sample Output Your Name 200 use a main function.
You are given a text file containing a short text. Write a program that 1. Reads...
You are given a text file containing a short text. Write a program that 1. Reads a given text file : shortText.txt 2. Display the text as it is 3. Prints the number of lines 4. Prints the occurences of each letter that appears in the text. [uppercase and lowercase letter is treated the same]. 5. Prints the total number of special characters appear in the text. 6. Thedisplayofstep3,4and5aboveshouldbesaveinanoutputfile:occurencesText.txt write it in C++ programing Language
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT