Moving modest minimum Inspired by a question over at Stack Overflow. The title here is entirely my fault.



The challenge

Given a list of positive integers containing at least two entries, replace each number by the minimum of all entries excluding itself.

Test cases

[4 3 2 5]    -&gt;  [2 2 3 2]
[4 2 2 5]    -&gt;  [2 2 2 2]
[6 3 5 5 8]  -&gt;  [3 5 3 3 3]
[7 1]        -&gt;  [1 7]
[9 9]        -&gt;  [9 9]
[9 8 9]      -&gt;  [8 9 8]


Rules

The algorithm should theoretically work for any input size (greater than one) and values (positive integers). It's accepted if the program is limited by time, memory or data types and so only works for numbers up to a given value, or for input size up to a given value.

Programs or functions are allowed, in any programming language. Standard loopholes are forbidden.

Input can be taken by any reasonable means; and with any format. Same for output. Input and output formats may be different.

Shortest code in bytes wins.
Python 2, 41 bytes



lambda l:[sorted(l)[x==min(l)]for x in l]


Try it online!

For each element x we check whether x==min(l). If not, this is False, which is treated as 0 when used as a list index into sorted(l), giving the smallest element. Otherwise, it's True aka 1, giving the second-smallest element, since that element itself is smallest and should be ignored.