Using iterators to write in the structure being iterated through?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Jul 26 15:42:15 EDT 2006


Pierre Thibault, some people here surely know enough Python (and C++)
to solve your problem, but often the problem is understanding the
problem. I have understood your problem just partially, so the
following are just ideas.

First of all I suggest you to use a normal Python list to keep the
data, and later modify the code to use an array if it is too much slow
or if you need arrays to do some special things, like plotting, etc.
Developing using normal Python lists is a bit simpler.

With python you can redefine the __getitem__ and __setitem__ of an
object according to its crystal symmetries. Then you can define some
method like iterkeys that yields (with yield) the only indexes that the
symmetry allows to be set.

Then you can iterate on those indexes and update the values in the list
attribute.

Bye,
bearophile




More information about the Python-list mailing list