Find Median from Data Stream
Find Median from Data Stream
In this challenge, your task is to write a Python function that finds the median from a stream of numbers. The median is the value separating the higher half from the lower half of a data sample. If the number of data points is odd, the median is the middle number. If the number of data points is even, the median is the average of the two middle numbers.
Let's imagine that you're building a real-time statistics app for a school project that calculates the median of scores as they are entered. Your code should be efficient enough to handle lots of data without slowing down the app.
Your function should keep a running list of numbers and be able to return the median at any point.
Examples
find_median_from_data_stream([2, 3, 4, 5, 6]) # Returns: 4.0 find_median_from_data_stream([2, 3, 4, 5]) # Returns: 3.5 find_median_from_data_stream([12, 4, 5, 3, 8]) # Returns: 5.0 find_median_from_data_stream([7, 12, 3, 1, 6, 5]) # Returns: 5.5
Fun Twist!
Imagine you're the coder for a party, and your friends want to know the median of their favorite numbers at any time. Help them find the right value quickly!
Inputs
Arg 1:
[2,3,4,5,6]Expected Output
4.0Actual Output