Skip to main content

Timeline for Stack data structure in Python 3

Current License: CC BY-SA 4.0

17 events
when toggle format what by license comment
S Mar 19, 2020 at 9:23 history suggested Brijesh Kalkani CC BY-SA 4.0
Spelling correction
Mar 19, 2020 at 9:22 review Suggested edits
S Mar 19, 2020 at 9:23
Nov 22, 2019 at 12:42 vote accept Brijesh Kalkani
Jul 16, 2021 at 5:50
Nov 22, 2019 at 12:39 vote accept Brijesh Kalkani
Nov 22, 2019 at 12:40
Nov 19, 2019 at 4:24 history edited Right leg CC BY-SA 4.0
added 6 characters in body
Nov 19, 2019 at 2:50 comment added njzk2 __len__ should be len(self.data)
Nov 18, 2019 at 19:21 history edited Right leg CC BY-SA 4.0
added 428 characters in body
Nov 18, 2019 at 11:37 comment added Solomon Ucko For a queue, collections.deque would be best to avoid O(n) operations @MeesdeVries
Nov 17, 2019 at 20:47 comment added juhist The argument is information hiding. By making the list a hidden implementation detail (preferably prefixed with underscore), a stack can be used only via its regular interface. The implementation is easier to change, too (for example, to linked list) if the implementation is not part of the interface.
Nov 17, 2019 at 20:17 comment added Right leg Ok guys, thanks for the feedback! I updated my answer, taking all this discussion into account. That was truly enriching, and I defintely learnt things today.
Nov 17, 2019 at 20:14 history edited Right leg CC BY-SA 4.0
added 1603 characters in body
Nov 17, 2019 at 19:30 comment added Right leg @juhist I don't deny that your point is not valid, but I'm not sure I get it. In Python, a list is a collection to which elements can be appended, and from which elements can be removed in the inverse order of insertion - among other properties of course. From this standpoint, a stack is a kind of list as defined in Python. Therefore, it looks to me that inheritance is appropriate. What would be your arguments in favor of composition over inheritance, in this specific situation?
Nov 17, 2019 at 17:21 comment added juhist This suggestion to inherit completely fails "Composition over inheritance" principle.
Nov 17, 2019 at 10:28 comment added Voo Inheriting from list to implement a stack is pretty awful. The point of APIs is to provide specific limited, documented functionality. I don't want users to be able to access or modify the middle of my stack or be confused why my stack class even has this functionality. Whether you actually need a stack is a different question.
Nov 17, 2019 at 5:50 comment added Mees de Vries Isn't l.pop(0) an O(n) operation?
Nov 16, 2019 at 20:38 history edited Right leg CC BY-SA 4.0
added 253 characters in body; added 42 characters in body; added 5 characters in body
Nov 16, 2019 at 20:31 history answered Right leg CC BY-SA 4.0