you can mimic your semantic in Python by using a generator function acting as closure, defining a nested function roman_to_dec and returning it.
I don't have Python installed and am not a Py expert, so please accept my semantically equal Perl interpolation.
(untested)
sub generator { my %rtoa = ( M=>1000, D=>500, C=>100, L=>50, X=>10, V=>5, I=>1 ); my $c_nested = sub { reduce { $a+$b-$a%$b*2 } map { $rtoa{$_} } split//, uc(sh +ift); }; return $c_nested; } *roman_to_dec = generator();
NB: This will look much easier in Python because it's automatically dereferencing.
I suppose most Pythonistas would rather prefer making rtoa a class variable and using roman_to_dec as a method. TIMTOWTDI. ;-)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re^6: A short whishlist of Perl5 improvements leaping to Perl7
by LanX
in thread A short whishlist of Perl5 improvements leaping to Perl7
by rsFalse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |