filter is Python
Brian Kelley
bkelley at wi.mit.edu
Wed Jul 30 11:16:35 EDT 2003
Wiebke Pätzold wrote:
> Hi all!
>
> I have to work with MetaKit. My job is it to filter. For example: If I
> search for the initial letter "P", the programm should all results
> print with this characteristic.
> Couls somebody help me with this task?
>
> Wiebke
The metakit list is probably the place for this. See equi4.com for
instructions. That being said:
I assume you are filtering a table/view looking at some column. Let's
say the table is "foo" and the column is "bar".
def myfilter(row):
return row.bar[0] == "P"
# return the matching indices
indices = view.filter(myfilter)
# return a new view with only the matching rows
newview = view.remapwith(indices)
Here is a full example:
import metakit
storage = metakit.storage()
vw = storage.getas("test[bar:S]")
data = """My dog has fleas but he is a very good Pooch.
Sometimes he likes to Play""".split()
for d in data:
vw.append((d,))
def myfilter(row):
return row.bar[0] == "P"
indices = vw.filter(myfilter)
metakit.dump(indices)
newvw = vw.remapwith(indices)
metakit.dump(newvw)
More information about the Python-list
mailing list