[Tutor] is there a better way to do this?

Peter Otten __peter__ at web.de
Mon May 9 12:50:07 EDT 2016


Chris Roy-Smith wrote:

> Hi
> Python 3.4 Linux (ubuntu)
> 
> This code does what I want.
> curs is the result of a mysql query
> 
> 
> data = [[" " for x in range(9)] for y in range(count)]
> for (ddate, mood, walk, lag, sleep) in curs:
>          data[row][0]=ddate
>          data[row][1]=mood
>          data[row][2]=walk
>          data[row][3]=lag
>          data[row][4]=sleep
>          row +=1
> 
> 
> While I don't know a better way to do this, it seems a bit awkward, is
> there a better way?

Does `curs` give `count` records? If so:

data = [
   list(row) + [" "] * 4
   for row in curs
]



More information about the Tutor mailing list