actually I also need this often. I normally do item_dict=dict([*r.id,r) for r in db(db.items.id > 0).select()])
or item_dict=dict([*r.id,r) for r in db(db.items.id > 0).select().as_list ()]) not sure it is worth an API On Oct 28, 11:34 pm, Russell <russell.mcmur...@gmail.com> wrote: > Hi, > > The DAL Rows object returned by select is a list. But often a > dictionary with id as the key is what is needed (ie, a frequently used > lookup table). Typically I do this... > > item_list = db(db.items.id > 0).select() > item_dict = {} > for item in item_list: > item_dict[item.id] = item > > Is there a better way? Could the framework do this automatically? Or > does the framework already have the feature, it's just that I haven't > worked out how to use it properly? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---