Use python to write a code
Problem 1: Environmental Monitoring
You are given a nested list in which the sublists contain tuples!
Example:
samples = [ [('frog','H'), ('toad','D') ], [('trout','H'), ('salmon','S'), ('catfish','H')] ]
Here each species is either healthy H, dead D or sick S. Access the health status of a specified animal using multi-indexing.
Count how many are healthy using two nested for loops. List will be bigger and different on each version.
Python Code:
""" Python program for Environmental Monitoring """
# Dictionary that holds the health status of animals
samples = [ [('frog','H'), ('toad','D') ], [('trout','H'),
('salmon','S'), ('catfish','H')] ]
# Access the health status of a specified animal using
multi-indexing
# Accessing health status of salmon
print("\n Health status of salmon: " + samples[1][1][1])
# Count how many are healthy using two nested for loops
# Variable that holds the count
cnt=0;
# Outer loop to iterate over sub lists
for i in range(len(samples)):
# Inner for loop for iterating over each tuple
in sublist
for j in range(len(samples[i])):
# Checking health
status
if samples[i][j][1] ==
'H':
cnt = cnt + 1
# Printing results
print(" As a total %d animals are healthy.. " %(cnt))
______________________________________________________________________________________
Sample Run:

Use python to write a code Problem 1: Environmental Monitoring You are given a nested list...