[Tutor] what am I not understanding?
Alan Gauld
alan.gauld at btinternet.com
Tue Oct 21 14:39:08 CEST 2014
On 20/10/14 22:18, Clayton Kirkwood wrote:
> for each_line in key_name.splitlines():
> if ':' in each_line: #this design had to
> for key, value in [each_line.split(':')]: #see the last line
You shouldn't need the [] around split(), it generates a list for you.
In fact I'd expect the [] to break it since there will only be a single
element(a list) in the outer list.
> #I presume that they force the source to look and feel like a tuple or list,
No, they create a list with whatever strip() produces. Here is a simpler
example:
mylist = [1,2,3]
outerlist = [mylist]
outerlist is now [[1,2,3]]
> I think they force two strings into a two items of a tuple???
I think you might be referring to the unpacking of the list into
key,value above?
key,value = [2,3]
makes key=2 and value=3
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list