Computer Science
A file contains a list of telephone numbers in the following form:
Arvind 7258031
Sachin 7259197
The names contain only one word, the names and telephone numbers are separated by white spaces. Write program to read a file and display its contents in two columns.
Python File Handling
3 Likes
Answer
Let the file "telephone.txt" include the following sample records:
Arvind 7258031
Sachin 7259197
Karuna 8479939
with open("telephone.txt", "r") as file:
f = file.readlines()
for line in f:
name, number = line.split()
print(name, '\t\t' ,number)
Output
Arvind 7258031
Sachin 7259197
Karuna 8479939
Answered By
2 Likes
Related Questions
Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by a single space.
A file sports.dat contains information in following format:
Event - Participant
Write a function that would read contents from file sports.dat and creates a file named Atheletic.dat copying only those records from sports.dat where the event name is "Atheletics".Write a program to count the words "to" and "the" present in a text file "Poem.txt".
Write a function AMCount() in Python, which should read each character of a text file STORY.TXT, should count and display the occurrence of alphabets A and M (including small cases a and m too).
Example :
If the file content is as follows :
Updated information
As simplified by official websites.The EUCount() function should display the output as :
A or a : 4
M or m : 2