Op Tuesday 5 May 2015 15:57 CEST schreef Ian Kelly: > On May 5, 2015 5:46 AM, "Cecil Westerhof" <ce...@decebal.nl> wrote: >> >> Op Tuesday 5 May 2015 12:41 CEST schreef Steven D'Aprano: >> >>> # Untested. def get_message_slice(message_filename, start=0, >>> end=None, step=1): real_file = expanduser(message_filename) >>> messages = [] # FIXME: I assume this is expensive. Can we avoid >>> it? nr_of_messages = get_nr_of_messages(real_file) >> >> If I want to give the possibility to use negative values also, I >> need the value. > > You could make this call only if one of the boundaries is actually > negative. Then callers that provide positive values don't need to > pay the cost of that case.
You have a point there. I will think about it. > Alternatively, consider that it's common for slices of iterators to > disallow negative indices altogether, and question whether you > really need that. It was an idea I got from this newsgroup. :-D And I liked it, otherwise I would not have implemented it. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof -- https://mail.python.org/mailman/listinfo/python-list