Question

In: Computer Science

Initialize an empty hashtable, programmatically add 5 items (colors, names, fruits, etc.), use Write-Host to print...

Initialize an empty hashtable, programmatically add 5 items (colors, names, fruits, etc.), use Write-Host to print the keys and values separately, then remove one of the items and print the entire hashtable

POWERSHELL PLEASE!

Solutions

Expert Solution

Initializing an empty hashtable:

$hash = @{}

adding 5 items:

Syntax: $hash = @{ key1 = value1 ; key2 = value2; key3 = value3 ; key4=value4;key5=value5}

$hash = @{ ID = 1; Color = "Red" ; Name = "Bhanu"; Fruit="Apple" ; Shape = "Square"}

we can also use Ordered dictionaries to maintain the order in which entries are added as shown below:

$hash = [ordered]@{ ID = 1; Color = "Red" ; name = "Bhanu"; fruit="Apple" ; Shape = "Square"}

Print the keys using Write-host:

write-host("Print all hashtable keys")
$hash.keys

Output:

Print all hashtable keys
ID
Color
Name
Fruit
Shape

Print the Values using Write-host:

write-host("Print all hashtable values")
$hash.values

Output:

Print all hashtable values
1
Red
Bhanu
Apple
Square

Removing one of the item(Fruit):

write-host("Removing an item")

$hash.Remove("Fruit")

printing the entire hashtable:

$hash

Output:

Name                           Value    
----                           -----                                                    
ID                             1                                                        
Color                          Red
Name                           Bhanu                                                     
Shape                          Square 

Related Solutions

1.Suppose a dictionary Groceries maps items to quantities.     Write a python to print the names...
1.Suppose a dictionary Groceries maps items to quantities.     Write a python to print the names of the grocery items whose quantity exceeds 400.     For example, if groceries = {‘cake mixes’: 430, ‘cheese’:312, ‘Orange’:525, ‘candy bars’: 217}         The output will be                                 Cake mixes                                 Orange 2. which Python string method would be the best choice to print the number of time “the” occurs in a sentence entered by the user? Provide a one word answer. Just...
Write a Python program to (a) create a new empty stack. Then, (b) add items onto...
Write a Python program to (a) create a new empty stack. Then, (b) add items onto the stack. (c) Print the stack contents. (d) Remove an item off the stack, and (e) print the removed item. At the end, (f) print the new stack contents:
Write up how to use JMP for 5 items (or other statistical software) with instructions. Cite...
Write up how to use JMP for 5 items (or other statistical software) with instructions. Cite sources if needed. 1. How to import data and change data type (from nominal to interval/ratio level) 2. How to find descriptive statistics (mean, median, mode, variance, etc) 3. How to find confidence intervals 4. How to do linear regression 5. How to do ANOVA
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT