Re: Moving list entries from one list to another
by Bengt Richter other posts by this author
Jul 13 2002 9:34PM messages near this date
Re: Moving list entries from one list to another
|
Re: Moving list entries from one list to another
On Sat, 13 Jul 2002 22:37:44 +0200, JB <jblazi@[...].com> wrote:
> Emile van Sebille wrote:
>
> > JB
> >> I have two lists <list1> and <list2>. The entries of
> >> these lists have the format (id,rest), where <id> is a
> >> natural number. The list are sorted, the key is <id>.
> >
> > Your use of the term 'key' here is throwing me. Lists
> > don't have keys,
> > dicts do. Dicts aren't sorted. ;-/
>
> The list entries are tuples. The first element of a tuple is
> the sorting key. It is a natural number n, 0<=n<N, where N
> is the number of all entries. Some of the entries are in
> list1 and some of them in list2. I am working on a list
> view widget. list1 contains "visible lines" and list2 the
> invisible lines. The moving between the lists is brought
> about by changes of a user defined filter.
>
What about keeping all your lines in a single list, and just
filtering for purposes of generating the list view window?
OTOH, if you do want two lists, what about making them both
able to contain the full list, and just use None as a placeholder
when moving an element from one to the other? If your id numbers
are just the indices on the full set, you don't even need to
store them as data, since you know the range. And if you do
want a copy of one of the lists without the None placeholders,
you can use the builtin filter function to get non-False-evaluating
elements like
noNonesList = filter(None, alist).
(note that you will lose null strings that way though).
Now you just need a fast way to check both lists and see whether
your predicate says to swap corrensponding elements, which will be
None and something or something and None.
Gotta go...
Regards,
Bengt Richter
--
http://mail.python.org/mailman/listinfo/python-list
Thread:
JB
JB
Bengt Richter
JB
Alex Martelli
Bengt Richter
JB
JB
JB
JB
JB
JB
Bengt Richter
Alex Martelli
Alex Martelli
Alex Martelli
Emile van Sebille
=?iso-8859-1?q?Fran=E7ois?= Pinard
|