Q:

Ruby program to print the inverted hash collection

0

In this program, we will create a hash collection. Then we will print the original and inverted hash collection, here we will invert key/value to each other.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to print the inverted hash collection is given below. The given program is compiled and executed on Windows 10 Operating System successfully.

# Ruby program to print the 
# inverted hash collection

student = {"101" => "Amit", "102" => "Arun", "103" => "Sumit"};

print "Original Hash collection: \n",student;
print "\nInverted hash collection: \n",student.invert();

Output:

Original Hash collection: 
{"101"=>"Amit", "102"=>"Arun", "103"=>"Sumit"}
Inverted hash collection: 
{"Amit"=>"101", "Arun"=>"102", "Sumit"=>"103"}

Explanation:

In the above program, we created a hash collection to store student information. Then we printed the inverted hash collection using the invert() m

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now