[Tutor] Object oriented design

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Dec 22 03:08:30 EST 2015


On 22/12/2015 02:15, Danny Yoo wrote:
> On Mon, Dec 21, 2015 at 5:58 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>> On 22/12/15 00:14, jamie hu wrote:
>>
>>>     Thanks Alan. I was thinking about making a list of objects and search
>>>     through it, but wasn't sure if that was right way.
>>
>> For small numbers of objects( aa few hundreds say) its the easiest option.
>
> If the data is small, it likely doesn't matter too much if you're
> using an unsorted list.
>
> For anything larger, but still in-memory, you may eventually want to
> start considering the appropriate data structures for the operations
> you're performing.  That's the kind of stuff a standard
> data-structures/algorithms course talks about.
>
> If we want to support exact lookups by key, a dictionary may be an
> appropriate choice.  But we shouldn't immediately discount a sorted
> list: binary search might also be appropriate.
> (https://docs.python.org/3.1/library/bisect.html).  It's another
> design choice that hinges on what operations we want to make go fast.

Theses are useful if you don't want to roll your own 
https://pypi.python.org/pypi/sortedcontainers

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list