Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom-set: implement exercise #1140

Merged
merged 10 commits into from
Jan 19, 2018

Conversation

cmccandless
Copy link
Contributor

@cmccandless cmccandless commented Dec 19, 2017

Resolves #746

@cmccandless
Copy link
Contributor Author

Canonical data

self.elements = list(elements)

def empty(self):
return not any(self.elements)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be return not self.elements - the current version would wrongly return True if self.elements == [0]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch... fixing.

def subset(self, other):
pass

def disjoint(self, other):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be isdisjoint and issubset to match with Python's implementation of set. I would also then change empty to isempty for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

return not any(self.elements)

def __iter__(self):
return iter(self.elements)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__iter__ is a kind of useful method to implement here, but I think that __contains__ would be a more logical for testing whether a set contains a particular value. Presumably __iter__ is providing that functionality here, but from a learner point of view, I don't think that this would be clear enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow was not aware of the __contains__ method previously, and though that implementing __iter__ was the correct way of supporting the in operator... I will fix this, thanks!

@N-Parsons N-Parsons merged commit 09de6ff into exercism:master Jan 19, 2018
@cmccandless cmccandless deleted the implement-custom-set branch August 5, 2019 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants