filter is Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wiebke Pätzold

    filter is Python

    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
  • Brian Kelley

    #2
    Re: filter is Python

    Wiebke Pätzold wrote:[color=blue]
    > 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[/color]

    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(myf ilter)
    # 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(myfil ter)
    metakit.dump(in dices)

    newvw = vw.remapwith(in dices)
    metakit.dump(ne wvw)


    Comment

    Working...