I am trying to translate a line of Perl code to Python, but I came to a roadblock on Python's sorted() method. Python does not have native hash support like in Perl, so i used autodict() to replicate the hash behavior of Perl. Below is the code snippet on how the sorting was done.
Perl:
hash{one}{"index"} = 1
hash{one}{"value"} = "uno"
hash{two}{"index"} = 2
hash{two}{"value"} = "dos"
hash{three}{"index"} = 3
hash{three}{"value"} = "tres"
foreach my $ctg (sort hash{$a}{"index"} <=> hash{$b}{"index"}} keys %{ hash })
Python:
hash[one]["index"] = 1
hash[one]["value"] = "uno"
hash[two]["index"] = 2
hash[two]["value"] = "dos"
hash[three]["index"] = 3
hash[three]["value"] = "tres"
for ctg in sorted(hash):
The translation above wasn't exactly correct. The Python version is sorting based on the 1st element in the hash which is one, two, three. But the Perl version is doing sort based on "index"