10. Write a python program to read a file, a.txt line by line and store it into an array..
The output is:
Original file a.txt:
Welcome to
www.freelearningpoints.com
You can learn Python tutorials and
practice with exercises
To practice with more exercises and
enhance the skills.
Expected Answer:
The total number of each words in the file :
['Welcome to\n', 'www.freelearningpoints.com\n', 'You can learn Python tutorials and\n',
'practice with exercises\n']
Sample Answer:
def read_file(file_name): array_result = [] with open(file_name) as f: for line in f: array_result.append(line) print(array_result) read_file('a.txt')
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)