Title: Python Program to Find Peaks in a List of Integers
Write a Python program function that uses a list of integers, test_list, and prints a list of peaks, which are numbers that are strictly greater than both of its neighbors.
IMPORTANT NOTES:
- The first and last values cannot be peaks.
- The same value might be a peak in multiple places in the original list.
- There might be no peaks, in which case you should simply return an empty list.
Sample Inputs/Outputs:
Example 1:
test_list = [1, 2, 3, 2, 1]
Expected Output: [3]
because: 3 > 2 and 3 > 2
Example 2:
test_list = [10, 2, 20, 3, 4, 4, 5, 8, 4, 5, 1]
Expected Output: [20, 8, 5]
because: 20 > 2 and 20 > 3; 8 > 5 and 8 > 4; 5 > 4 and 5 > 1.
LAB ACTIVITY 13.42.1: Find Peaks (Loops-Medium)
Current file: test_data.py
Load default template...
1. Corrected_text:
Title: Python Program to Find Peaks in a List of Integers
Write a Python program function that uses a list of integers, test_list, and prints a list of peaks, which are numbers that are strictly greater than both of its neighbors.
IMPORTANT NOTES:
- The first and last values cannot be peaks.
- The same value might be a peak in multiple places in the original list.
- There might be no peaks, in which case you should simply return an empty list.
Sample Inputs/Outputs:
Example 1:
test_list = [1, 2, 3, 2, 1]
Expected Output: [3]
because: 3 > 2 and 3 > 2
Example 2:
test_list = [10, 2, 20, 3, 4, 4, 5, 8, 4, 5, 1]
Expected Output: [20, 8, 5]
because: 20 > 2 and 20 > 3; 8 > 5 and 8 > 4; 5 > 4 and 5 > 1.
LAB ACTIVITY 13.42.1: Find Peaks (Loops-Medium)
Current file: test_data.py
Load default template...