Nested string substitutions
Lulu of the Lotus-Eaters
mertz at gnosis.cx
Fri Dec 20 22:16:43 EST 2002
|def expand(d):
| while filter(lambda (n, v): d.__setitem__(n,
| reduce(lambda x,k: x.replace(k, d[k]), d, v)
| ) or v!=d[n], d.items()): pass
Wow! Who ever said Perl was hard to read :-). How long did that take
to think of, Holger?
As marvelous as this is, what I am going with is basically what Mike
Meyer proposed:
def nested_expand(subs):
def expand(key, dict):
previous = ""
while previous != dict[key]:
previous = dict[key]
for old, new in dict.items():
dict[key] = dict[key].replace(old, new)
map(lambda x: expand(x, subs), subs.keys())
Yours, Lulu...
--
Keeping medicines from the bloodstreams of the sick; food from the bellies
of the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons. Intellectual
property is to the 21st century what the slave trade was to the 16th.
More information about the Python-list
mailing list