Implement a function that sorts a 2D list of glass types based on their densities. The function should take a list of lists, where each sublist represents a row of glass types, and return a new 2D list sorted such that each row retains the same number of elements but the elements are arranged in order of their densities.
Input/Output Requirements
Input: A 2D list glass containing strings representing different types of glass. Each string will be one of the following characters:
'H' (density 1.36)
'W' (density 1.00)
'A' (density 0.87)
'O' (density 0.80)
If the input list is empty ([]), the function should return an empty list.
Output: A 2D list where the glass types are sorted according to their densities in ascending order. The number of columns in the output should match the number of columns in the input.
Implementation Requirement
The function should be defined with the signature:
python
def sort_glass_by_density(glass):
File Requirement
Write the implementation in a file called /app/solution.py.
Example
Given the input:
python
[
['H', 'W'],
['A', 'O']
]
The output should be:
python
[
['O', 'A'],
['W', 'H']
]
Constraints
The input will only consist of the characters 'H', 'W', 'A', and 'O'. Each sublist will have the same length.