ForNext
Only Do What Only You Can Do
134. invert
Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby より (2012.05.08)
VBScript
JScript
Perl
%to_num = (t=>1, f=>0); %to_let = reverse %to_num;
PHP
$to_num = array("t"=>1, "f"=>0); $to_let = array_flip($to_num);
Python
to_num = {'t':1, 'f':0} # dict comprehensions added in 2.7: to_let = {v:k for k, v in to_num.items()}
Ruby
to_num = {"t"=>1, "f"=>0} to_let = to_num.invert