Apr-14-2022, 04:30 PM
First, you need to have a reference or your learning will be very slow. Here is the documentation for Python: https://docs.python.org/3/
Now, answering your specific question -
First line opens the file "file.txt" for reading and associates that file with the variable "readfile1"
Next line reads the contents of that file as a list of lines, assigns that list the name f
Next you create a new empty list called newList (btw - that variable name is called CamelCase and is frowned upon in Python. Better to use new_list)
Then you start a loop, through each item in the list f you strip the whitespace off the item and append it to the new list
Finally you print the new list.
Now, answering your specific question -
First line opens the file "file.txt" for reading and associates that file with the variable "readfile1"
Next line reads the contents of that file as a list of lines, assigns that list the name f
Next you create a new empty list called newList (btw - that variable name is called CamelCase and is frowned upon in Python. Better to use new_list)
Then you start a loop, through each item in the list f you strip the whitespace off the item and append it to the new list
Finally you print the new list.