Skip to content

Replace double_ended_queue.py #5429

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

Merged
merged 9 commits into from
Oct 21, 2021
Merged

Replace double_ended_queue.py #5429

merged 9 commits into from
Oct 21, 2021

Conversation

bqwstt
Copy link
Contributor

@bqwstt bqwstt commented Oct 19, 2021

Replaced double_ended_queue.py with an implementation of it with nodes.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added awaiting reviews This PR is ready to be reviewed require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 19, 2021
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

@ghost ghost removed require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 19, 2021
@poyea
Copy link
Member

poyea commented Oct 19, 2021

We can replace this file https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/double_ended_queue.py with your implementation, but use collections.deque in tests. Do you agree with this approach? @grbenjamin We can then demonstrate both implementations.

@ghost ghost added the tests are failing Do not merge until tests pass label Oct 19, 2021
@bqwstt
Copy link
Contributor Author

bqwstt commented Oct 19, 2021

We can replace this file https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/double_ended_queue.py with your implementation, but use collections.deque in tests. Do you agree with this approach? @grbenjamin We can then demonstrate both implementations.

@poyea I do! I added the comparison on each doctest. Tell me if it's ok.
I also added extend() and extendleft(), to make it a bit more complete.

@bqwstt
Copy link
Contributor Author

bqwstt commented Oct 19, 2021

Fixed issues with pre-commit. Hopefully that works.

@ghost ghost removed the tests are failing Do not merge until tests pass label Oct 19, 2021
values_list.append(aux.val)
aux = aux.next

return "[" + ", ".join(repr(val) for val in values_list) + "]"
Copy link
Member

Choose a reason for hiding this comment

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

https://docs.python.org/3/library/doctest.html

if __name__ == "__main__":
    import doctest

    doctest.testmod()

@poyea
Copy link
Member

poyea commented Oct 20, 2021

@grbenjamin Please simply use this file to replace the existing data_structures/queue/double_ended_queue.py and use collections.deque in docstrings for testing.

We can replace this file https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/double_ended_queue.py with your implementation, but use collections.deque in tests. Do you agree with this approach? @grbenjamin We can then demonstrate both implementations.

@poyea
Copy link
Member

poyea commented Oct 20, 2021

I guess we can do:

list(built_in_deque) == list(our_deque)

?

@bqwstt
Copy link
Contributor Author

bqwstt commented Oct 20, 2021

@grbenjamin Please simply use this file to replace the existing data_structures/queue/double_ended_queue.py and use collections.deque in docstrings for testing.

We can replace this file https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/double_ended_queue.py with your implementation, but use collections.deque in tests. Do you agree with this approach? @grbenjamin We can then demonstrate both implementations.

Please provide an example of use of collections.deque in docstrings, I don't really understand what you mean. Is the way I do it incorrect?

@bqwstt
Copy link
Contributor Author

bqwstt commented Oct 20, 2021

I guess we can do:

list(built_in_deque) == list(our_deque)

?

In

def is_empty(self) -> bool:
    """
    >>> ...
    >>> list(built_in_deque) == list(our_deque)
    """
    ...

? Or in all other doctests? @poyea

@poyea
Copy link
Member

poyea commented Oct 20, 2021

I guess we can do:

list(built_in_deque) == list(our_deque)

?

In

def is_empty(self) -> bool:
    """
    >>> ...
    >>> list(built_in_deque) == list(our_deque)
    """
    ...

? Or in all other doctests? @poyea

@grbenjamin Yes, something like this, wherever we want to test the implementation : https://docs.python.org/3/library/collections.html?highlight=deque#collections.deque
we can do this in all other doctests

@poyea
Copy link
Member

poyea commented Oct 20, 2021

@grbenjamin Please simply use this file to replace the existing data_structures/queue/double_ended_queue.py and use collections.deque in docstrings for testing.

We can replace this file https://github.com/TheAlgorithms/Python/blob/master/data_structures/queue/double_ended_queue.py with your implementation, but use collections.deque in tests. Do you agree with this approach? @grbenjamin We can then demonstrate both implementations.

Please provide an example of use of collections.deque in docstrings, I don't really understand what you mean. Is the way I do it incorrect?

>>> from collections import deque
>>> d_collections = deque('123456')

etc.

@bqwstt
Copy link
Contributor Author

bqwstt commented Oct 20, 2021

Done, replaced the existing file and added more tests.

@bqwstt bqwstt changed the title Add deque_from_scratch.py Replace double_ended_queue.py Oct 20, 2021
@bqwstt bqwstt requested a review from poyea October 20, 2021 18:42
Copy link
Member

@poyea poyea left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you for your pull request!🤩

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Oct 21, 2021
@poyea poyea merged commit 2e955ae into TheAlgorithms:master Oct 21, 2021
@bqwstt bqwstt deleted the deque_scratch branch October 21, 2021 13:40
shermanhui pushed a commit to shermanhui/Python that referenced this pull request Oct 22, 2021
* Add deque_from_scratch.py

* added deque_from_scratch.py

* add extend, extendleft and make comparison

* updated operations list

* fix doctest on Deque.__iter__

* pre-commit fix

* time complexity comments, change type hints

* pre-commit fix

* added more doctests
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