Re: Help with sets

On Tue, Oct 5, 2010 at 12:01 AM, Ian Kelly <ian.g.kelly@xxxxxxxxx> wrote:
On Mon, Oct 4, 2010 at 8:31 PM, B. M. Whealton
<bwhealton@xxxxxxxxxxxxxxxxxxxxx> wrote:

self._pos = {predicate:{object:set([subject])}}

      We have the first dictionary keyed off the first term, the second
dictionary keyed off the second term, and the set containing the third
terms(note terms plural). I guess I somewhat understand that sets are used
to test for membership.  Cannot that be done with dictionaries, though?

You could.  I suspect the pertinent difference here is that dict keys have
values associated with them.  The same code using a dict as the innermost
collection would look something like this:

self._pos = {predicate: {object: {subject: None}}}

That's a bit ugly because the None serves no purpose here; the value
associated with the subject has no meaning in this context.  It also
uselessly takes up space in memory that could add up to significant wastage
if the data structure grows to be large.

Indeed, CPython's sets are implemented as something like dictionaries
with dummy values (the keys being the members of the set), with some
optimization(s) that exploit this lack of values.


Relevant Pages

  • Re: Take this real test and see which President you side with.
    ... Now if Obama wins a second term, will you form a militia group and ...   I'm also a firm ... and each other when they work hard and make their own money instead of ... But people tend to be happier when they're treated like ...
  • Re: Login Script Help
    ... ' Check membership in group "Test". ...     ' User is a member of the group. ... If you must use group NetBIOS names, I would suggest using the NameTranslate ... ' Constants for the NameTranslate object. ...
  • Re: Unions
    ...   I am curious if most of this group is union or non-union ... - or perhaps union, but not AFM. ... Union membership is declining. ... I have been an afm member for many years. ...
  • Re: Lets do a Little Self-reflection
    ... membership to our group is that we act like dicks towards new posters ... trying to be uber-snarky and uber-cool, we might not have a membership ...   ...
  • Re: Active Directory User Membership limit
    ... I was hoping a command line tool like adfind or dsquery could get this ... VBScript program dumps out the Distinguished Names of all users in the ...     ' Retrieve values. ... security group membership (including the "primary" group and membership ...