Shakespeare: Difference between revisions

imported>Zanwenhuahao
imported>Zanwenhuahao
Line 101:
<pre>
>>> lst = open("importList.txt").readlines()
 
# readlines.() reads each line in the file and puts each line as a string and saves them all to the list called lst.
 
>>> lst
['apple\n', 'pear\n', 'oranges\n', 'kiwi\n', 'banana\n', 'monkey']
 
# notice that there are these weird '\n' characters following each item, they are the newline symbols (when you hit enter to start a new line)
# we can remove them as such
 
>>> lstFinal = [eachthing.strip("\n") for eachthing in lst]
>>> lstFinal
Anonymous user