Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6247629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:54:42+00:00 2026-05-24T12:54:42+00:00

Given the following hash: {7=>Ada (gnat-4.3.2), 13=>Assembler (nasm-2.07), 45=>Assembler (gcc-4.3.4), 104=>AWK (gawk) (gawk-3.1.6), 105=>AWK

  • 0

Given the following hash:

{"7"=>"Ada (gnat-4.3.2)", "13"=>"Assembler (nasm-2.07)", "45"=>"Assembler (gcc-4.3.4)", "104"=>"AWK (gawk) (gawk-3.1.6)", "105"=>"AWK (mawk) (mawk-1.3.3)", "28"=>"Bash (bash 4.0.35)", "110"=>"bc (bc-1.06.95)", "12"=>"Brainf**k (bff-1.0.3.1)", "11"=>"C (gcc-4.3.4)", "27"=>"C# (mono-2.8)", "1"=>"C++ (gcc-4.3.4)", "44"=>"C++0x (gcc-4.5.1)", "34"=>"C99 strict (gcc-4.3.4)", "14"=>"CLIPS (clips 6.24)", "111"=>"Clojure (clojure 1.1.0)", "118"=>"COBOL (open-cobol-1.0)", "106"=>"COBOL 85 (tinycobol-0.65.9)", "32"=>"Common Lisp (clisp) (clisp 2.47)", "102"=>"D (dmd) (dmd-2.042)", "36"=>"Erlang (erl-5.7.3)", "124"=>"F# (fsharp-2.0.0)", "123"=>"Factor (factor-0.93)", "125"=>"Falcon (falcon-0.9.6.6)", "107"=>"Forth (gforth-0.7.0)", "5"=>"Fortran (gfortran-4.3.4)", "114"=>"Go (gc-2010-07-14)", "121"=>"Groovy (groovy-1.7)", "21"=>"Haskell (ghc-6.8.2)", "16"=>"Icon (iconc 9.4.3)", "9"=>"Intercal (c-intercal 28.0-r1)", "10"=>"Java (sun-jdk-1.6.0.17)", "35"=>"JavaScript (rhino) (rhino-1.6.5)", "112"=>"JavaScript (spidermonkey) (spidermonkey-1.7)", "26"=>"Lua (luac 5.1.4)", "30"=>"Nemerle (ncc 0.9.3)", "25"=>"Nice (nicec 0.9.6)", "122"=>"Nimrod (nimrod-0.8.8)", "43"=>"Objective-C (gcc-4.5.1)", "8"=>"Ocaml (ocamlopt 3.10.2)", "119"=>"Oz (mozart-1.4.0)", "22"=>"Pascal (fpc) (fpc 2.2.0)", "2"=>"Pascal (gpc) (gpc 20070904)", "3"=>"Perl (perl 5.12.1)", "54"=>"Perl 6 (rakudo-2010.08)", "29"=>"PHP (php 5.2.11)", "19"=>"Pike (pike 7.6.86)", "108"=>"Prolog (gnu) (gprolog-1.3.1)", "15"=>"Prolog (swi) (swipl 5.6.64)", "4"=>"Python (python 2.6.4)", "116"=>"Python 3 (python-3.1.2)", "117"=>"R (R-2.11.1)", "17"=>"Ruby (ruby-1.9.2)", "39"=>"Scala (scala-2.8.0.final)", "33"=>"Scheme (guile) (guile 1.8.5)", "23"=>"Smalltalk (gst 3.1)", "40"=>"SQL (sqlite3-3.7.3)", "38"=>"Tcl (tclsh 8.5.7)", "62"=>"Text (text 6.10)", "115"=>"Unlambda (unlambda-2.0.0)", "101"=>"Visual Basic .NET (mono-2.4.2.3)", "6"=>"Whitespace (wspace 0.3)"} 

I want a hash ordered by the integer value of the hash key.

So far I’ve tried

languages.sort_by {|k| k[0].to_i }

and

languages.sort

where the first returns an array, and the second doesn’t order by the integer value of the key(so the order is evidently wrong).

In the end I would like to have something like:

{"1" => "C++ (gcc-4.3.4)", "2" => "Pascal (gpc) (gpc 20070904)", ... }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:54:42+00:00Added an answer on May 24, 2026 at 12:54 pm

    Nice and simple (for 1.9):

    hs = Hash[h.sort_by {|k,v| k.to_i }]
    

    For example:

    >> h = { '23' => 'twenty three', '11' => 'eleven', '42' => 'forty two', '1' => 'one' }
    => {"23"=>"twenty three", "11"=>"eleven", "42"=>"forty two", "1"=>"one"}
    >> hs = Hash[h.sort_by {|k,v| k.to_i }]
    => {"1"=>"one", "11"=>"eleven", "23"=>"twenty three", "42"=>"forty two"}
    

    And for more recent Rubies:

    hs = h.sort_by { |k, _| k.to_i }.to_h
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code #!/usr/bin/perl use Data::Dumper; my %hash; my @colos = qw(ac4 ch1
For example Given an array: array = [[:a,:b],[:a,:c],[:c,:b]] Return the following hash: hash =
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?
Installing egit on indigo im given following options : I've just checked 'Eclipse Egit'
Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
Given the following code: final class retVal { int photo_id; } Gson gson =
Given the following XML: <Contact> <ContactID>41111-f15a-4fa1-b643-47877608f557</ContactID> <ContactStatus>ACTIVE</ContactStatus> <Name>ABC Ltd</Name> <EmailAddress>xxx@xxx.co</EmailAddress> <SkypeUserName>xxxdemo</SkypeUserName> <Addresses> <Address> <AddressType>STREET</AddressType>
Given the following models: team.rb class Team < ActiveRecord::Base has_many :events, :dependent => :destroy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.