+ 1
how to write code to detect middle number in python array
ex- a= {2,3,5} mid=3 b={1,1,5,6,7} mid=5
3 Respostas
+ 6
Is that an array or a `set`?
You know that the latter cannot have duplicate members. So if it was a `set`, <b> will have {1, 5, 6, 7} only
Should it return a single value even when the container has even number of elements? I was thinking, if <b> has {1, 5, 6, 7} there would be 2 middle numbers, 5 and 6 ...
What if the container only has 2 members in? e.g. [ 20, 23 ] or a single member like [ 2023 ] ?
+ 5
Roshaan, good decision.
But I think that
middleNum = (len(array) - 1) // 2 = len(array) // 2
+ 1
Damsara Welivita that is not an array I agree with Ipang