A couple of weeks in the past, I wrote one other article to elucidate the mechanisms and logic behind some fashionable “Python Methods”. Considered one of them is to make use of Python Set however not Record once we can.
After this text turned fashionable, many readers requested me or argued that Python Set isn’t at all times quick. That’s completely true. Due to this fact, I made a decision to write down this text to have a deep dive into the information constructions of Python Record and Set.
On this article, I’ll first use sensible code to match the efficiency between Python Record and Set in numerous situations. Then, I’ll introduce the information constructions they used, that are Dynamic Array and Hash Desk. Based mostly on the traits of those knowledge constructions, I’ll clarify why Python Record or Set has higher efficiency in sure situations.