ForNext
Only Do What Only You Can Do
132. from array of pairs, from even length array
Hyperpolyglot Interpreted Languages: PHP, Perl, Python, Ruby より (2012.05.08)
VBScript
JScript
Perl
@a = (1,"a",2,"b",3,"c"); %d = @a;
PHP
Python
a = [[1,'a'], [2,'b'], [3,'c']] d = dict(a) a = [1,'a',2,'b',3,'c'] d = dict(zip(a[::2], a[1::2]))
Ruby
a = [[1,"a"], [2,"b"], [3,"c"]] d = Hash[a] a = [1,"a",2,"b",3,"c"] d = Hash[*a]