Quick actions

cmd+k|ctrl+k

Navigation

Languages

median of an array

Snippet info

Language

Python

Visibility

public

Author

krishnakanth

Created

2022-12-16T17:22:35.318554Z

Updated

2022-12-16T17:46:27.569714Z

arr = [2.4, 5.1, 6.7, 8.9]

arr.sort()

if len(arr)%2 == 0:
    res = (arr[round(len(arr)/2) - 1] + arr[round(len(arr)/2)])/2
else:
    res = arr[int(len(arr)/2)]
    
print(res)
INFO