On Mon, Dec 21, 2015 at 5:58 PM, Alan Gauld <[email protected]> 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. _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
