Feature Structures in Python (Part I)

Andrew Bennetts andrew-pythonlist at puzzling.org
Thu Jun 19 01:59:03 EDT 2003


On Thu, Jun 19, 2003 at 01:31:41PM +0800, James Tauber wrote:
> 
> This is the first part of a tutorial/cookbook I'm writing up on
> implementing feature structures in Python.

What's a "feature structure"?

> I'd love any feedback (particularly on the Pythonicity of my approach).

[...]

> # The del operator can be used to remove features. For example

Actually, del is a statement.

> del fs5[HEAD][AGR][NUMBER]

[...]

> # If you wish to delete all features in a particular structure or
> # sub-structure, you can iterate over the keys of the dictionary and
> # delete each one.

But you'd be better off just using the .clear() method of dicts.

> for f in fs5[HEAD][SUBJ][AGR].keys():
>     del fs5[HEAD][SUBJ][AGR][f]

So this would become simply:

    fs5[HEAD][SUBJ][AGR][f].clear()

-Andrew.






More information about the Python-list mailing list