Re: Dictionary of tuples from query question

2005-11-14 Thread David Pratt
Thanks Fredrik for your help. Really short and efficient - very nice! Regards, David On Monday, November 14, 2005, at 12:12 PM, Fredrik Lundh wrote: > I meant to write > > d = {} > for index, record in enumerate(cursor.fetchall()): > d[index+1] = tuple(record) > > which can be sh

Re: Dictionary of tuples from query question

2005-11-14 Thread Fredrik Lundh
David Pratt wrote: > Hi Fredrik. Many thanks for your reply and for the tuple tip. The > cursor.fetchall returns a list of lists in this instance with each list > in the main list containing the field values. With the tip, I > simplified my code to: > > vlist_dict = {} > record_count = 0 > for rec

Re: Dictionary of tuples from query question

2005-11-14 Thread Ben Sizer
David Pratt wrote: > With the tip, I > simplified my code to: > > vlist_dict = {} > record_count = 0 > for record in cursor.fetchall(): > record_count += 1 > vlist_dict[record_count] = tuple(record) > print vlist_dict I missed your original post, so forgive me if I'm missing the point

Re: Dictionary of tuples from query question

2005-11-14 Thread David Pratt
Hi Fredrik. Many thanks for your reply and for the tuple tip. The cursor.fetchall returns a list of lists in this instance with each list in the main list containing the field values. With the tip, I simplified my code to: vlist_dict = {} record_count = 0 for record in cursor.fetchall():

Re: Dictionary of tuples from query question

2005-11-14 Thread Fredrik Lundh
David Pratt wrote: > My code so far. I guess my problem is how to generate a tuple > dynamically when it is immutable? you can use tuple() to convert lists to tuples. >>> x = [] >>> x.append(1) >>> x.append(2) >>> x.append(3) >>> tuple(x) (1, 2, 3) but doesn't fetchall a

Dictionary of tuples from query question

2005-11-13 Thread David Pratt
Hi. I am interested in having results from a db query in the following form. {1: (value0, value1, value2,), 2: (value0, value1, value2,), 3: (value0, value1, value2,)} so I generate a dictionary of tuples (field values) dynamically so if I queried a table with five fields I would have five field