0

I have

query= (db.mytable.ref_other_table==other_table_id)
rows=db(query).select()

How can I find a row in rows, knowing the records id, for instance, I can do

ix=0
while rows[ix].id != id:
    ix+=1

but is this the most efficient way?

Ben Law
  • 58
  • 6

1 Answers1

1
row = rows.find(lambda r: r.id == some_id)

However, depending on how many records are in rows, it could actually be faster to just retrieve the record directly from the database:

row = db.mytable(some_id)
Anthony
  • 25,466
  • 3
  • 28
  • 57