Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python NDB: what's the best way to have a Set instead of a List in property?

in NDB you have repeated properties, they behave just like a native python list but i want them to behave just like native sets. i need to have a set of keys that is without duplicates. in python you can remove duplicates like the_list = list(set(the_list)),

but how would you implement this so it is automatic and i don't to think about this ?

like image 318
user47376 Avatar asked Feb 01 '26 18:02

user47376


1 Answers

Three ways come to mind:

  1. enforce the list (repeated property) is unique with a "setter" method that only inserts unique values;
  2. likewise, enforce the list is unique with a _pre_put_hook() method;
  3. use the key on each entity as your list, ndb will make sure they are unique.
like image 104
Brent Washburne Avatar answered Feb 04 '26 07:02

Brent Washburne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!