what's going on here?

Felipe Almeida Lessa felipe.lessa at gmail.com
Thu Mar 16 11:48:19 EST 2006


Em Qui, 2006-03-16 às 16:31 +0000, John Salerno escreveu:
> So finally here's my question: If you are using data.append(), doesn't 
> that just put all the numbers into one long list? How are the tuples 
> still being created in this case so that the list comprehensions still 
> work? It seems like there is no longer any 'row' to refer to in data.

Look the line """data.append(map(float, line.split()))"""

In other words:

# Suppose line is "2004    12      34.2    35.2    33.2"
# for our comments

# Creates a list, like ["2004", "12", "34.2", "35.2", "33.2"]
splitted = line.split() 

# Convert all numbers to floats
numbers = map(float, splitted)

# It could also be
# numbers = [float(x) for x in splitted]

# Append the list to the data
# ReportLab accept both lists and tuples, so it doesn't matter
data.append(numbers)


Hope this clarifies your mind,
Felipe.




More information about the Python-list mailing list