Google App Engine Python - sort by density in ListProperty
Is that possible to return a db result which sort by density matching in ListProperty
For example, I have a db.ListProperty(basestring)
with below value:
list_A = ['a1','a2','a3','a4','a5']
list_B = ['b1','b2','b3','b4','b5']
list_C = ['a1','a2','b1','b2','b3']
giving to_be_match_list = ['a1','b1','b2']
and return result in order of density match
list_C return 1st, matching a1, b1 and b2
list_B return 2nd, matching b1 and 开发者_如何学Pythonb2
list_A return last, matching a1
Thanks in advance.
No, you can't do that in BigTable (GQL).
If you grabbed all of the results, however, and wanted to sort them, you could do something like this:
some_lists = [list_A, list_B, list_C]
some_lists.sort(key=lambda x: len(set(to_be_match_list) & set(x)), reverse=True)
精彩评论