Creating a list with holes

Chris Angelico rosuav at gmail.com
Fri Jan 3 22:38:56 EST 2014


On Sat, Jan 4, 2014 at 2:32 PM, Dan Stromberg <drsalists at gmail.com> wrote:
> That is fine, sorting once at then end of a script is a good use of
> sorted(some_dict.keys()).  However, it probably should be pointed out
> that this, while similar, is not so good:
>
> for thing in range(n):
>    for key in sorted(some_dict.keys()):
>       do_something(thing, key)
>
> ...because it's sorting n times.

Oh! Yeah. Yeah, that would be inefficient.

ChrisA



More information about the Python-list mailing list