Skip to content

custom-set: implement exercise#1140

Merged
N-Parsons merged 10 commits into
exercism:masterfrom
cmccandless:implement-custom-set
Jan 19, 2018
Merged

custom-set: implement exercise#1140
N-Parsons merged 10 commits into
exercism:masterfrom
cmccandless:implement-custom-set

Conversation

@cmccandless
Copy link
Copy Markdown
Contributor

@cmccandless cmccandless commented Dec 19, 2017

Resolves #746

@cmccandless
Copy link
Copy Markdown
Contributor Author

Canonical data

Comment thread exercises/custom-set/example.py Outdated
self.elements = list(elements)

def empty(self):
return not any(self.elements)
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread exercises/custom-set/custom_set.py Outdated
def subset(self, other):
pass

def disjoint(self, other):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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