lists - append - unique and sorted

Diez B. Roggisch deets at nospam.web.de
Wed Jun 6 11:33:12 EDT 2007


rhXX wrote:

> hi,
> 
> can i append a item to a list using criterias:
> 
> - UNIQUE - if there already exist don't append

 
> - SORTED - INSERT in the correct place using some criteria?

Both can be accomplished using the bisect-module. It will give you the
leftmost/rightmost insertion point for a given item and a list, and then
you have to see if it is contained in between (or something along these
lines, I hope you get the gist of it)

Diez



More information about the Python-list mailing list