Hello!
# is used comment in python
list is the collection which is changable similar to array
map is used to map all the elements to the list variable
input() is used to get input in string format
split() is used to split all the elemets
rstrip() is used to strip '\n' and spaces
And i have explained more clearly using comments.
CODE:
def read_from_file_table():
# declare list of lists
list_of_lists=[]
# asks the user to enter file name
fname=input("Enter the filename:")+".txt"
# open file for read only
f=open(fname,"r")
# reads all the lines in the file
filedata=f.readlines()
# iterates over each line
for eachline in filedata:
# strips new line and splits all the numbers
line=eachline.rstrip().split()
# creates a list with empty elememts
list_for_each_line=[]
# iterates over every element in the line
for number in line:
# if the number is greater than 0
if(int(number)>=0):
# then only it wll append
list_for_each_line.append(int(number))
# finally appens the list of the line to list of lists
list_of_lists.append(list_for_each_line)
# prints the list of lists
print(list_of_lists)
# this code helps us to not let run immediately after import
# whenever function is called only it will executed
if __name__ == "__main__":
read_from_file_table()

TEXT FILE:
fIle1.txt
1 2 3
4 5
6
-8 -9 99
33

OUTPUT:

Hope this helps and clear.
Please feel free to comment if you have any doubts . If you face any difficulty please let me know i will help you with in few minutes.
I strive to provide the best of my knowledge so please upvote if you like the content.
Thank you!
using python The following shows the result of calling function read_from_file_sum_squares() for each of these two...
In Python please: plagiarism: This Boolean function takes two filenames. If any line occurs in both files, return True. If not, return False. I suggest using nested loops. With nested loops, we call the loop that is in the body of the other loop, the "inner loop". The loop that contains the inner loop is the "outer loop". Open the second file inside the outer loop: for line1 in file1: file2 = open(fname2) for line2 in file2:
Sample program run - Needs to be coded in python -Enter the text that you want to search for, Or DONE when finished: valiant paris The valiant Paris seeks for his love. -Enter the text that you want to search for, or DONE when finished: Romeo and Juliet Enter Romeo and Juliet aloft, at the WIndow -- Enter the text that you want to search for, DONE when finished: DONE # copy the following two lines into any # program...
Using the Python program be able to identify or discuss the following: A good test plan – how would you determine that it is working? Limitations of the program – what would you do to enhance it? Output improvement – what would you add to improve output? Examples of local variables – name, types, and scope Reason why global variables are not recommended Examples of constants Use of Boolean variable Use of floating point variable Use of integer variable Math...
PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots ... and have it be in the same directory as the Python program you are coding for this assignment. IMPORTANT: Your program should work with any size file. It should work with 100 items listed or with no items in the file! Write a Python program that ... 1....
python 3
HW11.2. Read a file and print its lines The function takes a single string parameter, which is the name of a file. Complete the function to open the file for reading, read the lines of the file, and print out each line. The function takes a single string parameter, which function to open the file for reading, read the lines student.py def print_lines of file (filename): 1
Python Language !
Use the Design Recipe to define a function save_history which consumes two parameters, a nested list and an int representing the current landing attempt. The function should open a new file named LandingNN.csv' where NN is two digits representing the current landing attempt. The first line should contain the number of sublists in the nested list. Each sublists should be written to the file on its own line with its values separated by commas. This function should...
In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...
Python 12.10 LAB: Sorting TV Shows (dictionaries and lists)
Write a program that first reads in the name of an input file
and then reads the input file using the file.readlines() method.
The input file contains an unsorted list of number of seasons
followed by the corresponding TV show. Your program should put the
contents of the input file into a dictionary where the number of
seasons are the keys, and a list of TV shows are the values (since...
For Python-3 I need help with First creating a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots. Write a python program that 1. Puts this as the first line... import os 2. Creates an empty list 3. Defines main() function that performs the tasks listed below when called. 4. Put these two lines at the top of the main function... if os.path.exists("costlist.txt"): os.remove("costlist.txt") Note: This removes the "costlist.txt" file, if it exists. 5....
For this problem, you have to use following hash function: key
modulo the number of buckets.
Input format: This program takes a file name as
argument from the command line. The file is either blank or
contains successive lines of input. Each line contains a character,
either ‘i’ or ‘s’, followed by a tab and then an integer, the same
format as in the Second Part. For each of the lines that starts
with ‘i’, your program should insert that...