简体   繁体   English

Google App Engine Python - 按ListProperty中的密度排序

[英]Google App Engine Python - sort by density in ListProperty

Is that possible to return a db result which sort by density matching in ListProperty 是否可以返回按ListProperty中的密度匹配排序的db结果

For example, I have a db.ListProperty(basestring) with below value: 例如,我有一个db.ListProperty(basestring) ,其值低于:

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 给出to_be_match_list = ['a1','b1','b2']并按密度匹配的顺序返回结果

list_C return 1st, matching a1, b1 and b2 list_C返回1st,匹配a1,b1和b2

list_B return 2nd, matching b1 and b2 list_B返回2nd,匹配b1和b2

list_A return last, matching a1 list_A返回最后一个,匹配a1

Thanks in advance. 提前致谢。

No, you can't do that in BigTable (GQL). 不,你不能在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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM