Commit 78d220eb authored by Jim Fulton's avatar Jim Fulton

Added a new "builtin" function reorder:

  reorder(s, [with, without]]) --

     Reorder the items in s according to the order given in with
     and with items mentioned in without removed.  Items from s
     not mentioned in with are removed.

     s, with, and without are all either sequences if strings
     or sequences of key-value tuples, with ordering done on the
     keys.

This function is useful for constructing ordered select lists.
parent d59049fb
...@@ -82,8 +82,8 @@ ...@@ -82,8 +82,8 @@
# attributions are listed in the accompanying credits file. # attributions are listed in the accompanying credits file.
# #
############################################################################## ##############################################################################
'''$Id: DT_Util.py,v 1.51 1999/03/10 00:15:07 klm Exp $''' '''$Id: DT_Util.py,v 1.52 1999/03/22 17:28:37 jim Exp $'''
__version__='$Revision: 1.51 $'[11:-2] __version__='$Revision: 1.52 $'[11:-2]
import regex, string, math, os import regex, string, math, os
from string import strip, join, atoi, lower, split, find from string import strip, join, atoi, lower, split, find
...@@ -242,6 +242,35 @@ def render(self, v, simple={ ...@@ -242,6 +242,35 @@ def render(self, v, simple={
d['render']=render d['render']=render
def reorder(self, s, with=None, without=()):
if with is None: with=s1
d={}
tt=type(())
for i in s1:
if type(i) is tt and len(i)==2: k, v = i
else: k= v = i
d[k]=v
r=[]
a=r.append
h=d.has_key
for i in without:
if type(i) is tt and len(i)==2: k, v = i
else: k= v = i
if h(k): del d[k]
for i in with:
if type(i) is tt and len(i)==2: k, v = i
else: k= v = i
if h(k):
a((k,d[k]))
del d[k]
return r
d['reorder']=reorder
expr_globals={ expr_globals={
'__builtins__':{}, '__builtins__':{},
'__guarded_mul__': VSEval.careful_mul, '__guarded_mul__': VSEval.careful_mul,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment