Here it is not clear why you are subscripting the result of the select with [i]. Presumably each query returns a single matching row, which means you want the subscript to always be [0] -- otherwise, you will get a list index out of range error.
Actually, given that you don't really need the index of each element in the list, you can instead just iterate over the list itself:
for item in getcourseids:
And if you did need the index values in addition to the elements, the more typical approach in Python would be:
for i, item in enumerate(getcourseids):
Anyway, in this case you should not be using the above method at all, as it is very inefficient (you are doing a separate database query for every single item in getcourseids, when you could instead use a single query). Villas has the right idea, but getcourseids.values() assumes getcourseids is a dictionary -- presumably it is actually a Rows object. So, you can do:
s = db(db.item.id.belongs([c.item_id for c in getcourseids])).select(db.item.course_title)
Note, the above is a Rows object. You can convert it to a list if you
really need a list, but most likely you can work with the Rows object
(it can be iterated and indexed just like a list).
Assuming getcourseids is a Rows object and the only reason it was created was to get the item_id values to be used in this subsequent query, you can instead skip the creation of getcourseids and just use a
nested select:
id_query = db([your query to retrieve course ids])._select(db.your_course_table.item_id)
s = db(db.item.id.belongs(id_query)).select(db.item.course_title)
Anthony