[Tutor] What's going on in this Python code from Programming Collective Intelligence?
Alan Gauld
alan.gauld at btinternet.com
Wed Jul 10 19:20:33 CEST 2013
On 10/07/13 13:05, Dave Angel wrote:
> mylist = [(row[0],0) for row in rows]
>
> I'll guess it's the list comprehension that confuses you. That line is
> roughly equivalent to:
> mylist = []
> for row in rows:
> mylist.append( (row[0], row) )
Except the second element in the tuple to append should be zero.
> So you end up with a list of tuples, each consisting of row[0] and
a zero
Presumably this will be the starting score for each item.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list