[Tutor] Semantic Error: Trying to access elements of list and append to empty list with for loop
Alan Gauld
alan.gauld at yahoo.co.uk
Thu Jun 2 13:18:04 EDT 2016
On 02/06/16 18:05, Olaoluwa Thomas wrote:
> lst = list()
> for line in fhand:
> words = line.split()
words is now a list of words
a test that a portion of my code was working)
> lst.append(words)
So you append that list to lst and get a list of lists.
Try using + instead:
lst += words
> would give me the output in the attached screenshot
> [image: Inline image 2]
This is a text based list attachments often get
stripped out by the server
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list