PYTHONJUNIORJOB Telegram 817
#вопрос235

Напишите функцию, которая будет принимать список чисел и возвращать два числа, абсолютная разность которых минимальна. Пару чисел нужно вернуть в виде списка, отсортированного по возрастанию.

Если в списке есть несколько пар чисел с одинаковой абсолютной разностью, выберите ту пару, которая в сумме даст наименьшее число.

В списке не будет дублирующихся значений.

Примеры:

min_difference_pair([40, 16, 8, 17, 15])
➞ [15, 16]
# Сумма [15, 16] меньше, чем сумма [16, 17]

min_difference_pair([1, -31, -27, -18, -48, -15, -11, -34])
➞ [-34, -31]

min_difference_pair([0, 2, 35, 42, 45, 14, -6, -1])
➞ [-1, 0]

min_difference_pair([32, 33, 4, 6, 48, 18, 20, -7, -4, 31])
➞ [31, 32]
🥴21



tgoop.com/pythonjuniorjob/817
Create:
Last Update:

#вопрос235

Напишите функцию, которая будет принимать список чисел и возвращать два числа, абсолютная разность которых минимальна. Пару чисел нужно вернуть в виде списка, отсортированного по возрастанию.

Если в списке есть несколько пар чисел с одинаковой абсолютной разностью, выберите ту пару, которая в сумме даст наименьшее число.

В списке не будет дублирующихся значений.

Примеры:

min_difference_pair([40, 16, 8, 17, 15])
➞ [15, 16]
# Сумма [15, 16] меньше, чем сумма [16, 17]

min_difference_pair([1, -31, -27, -18, -48, -15, -11, -34])
➞ [-34, -31]

min_difference_pair([0, 2, 35, 42, 45, 14, -6, -1])
➞ [-1, 0]

min_difference_pair([32, 33, 4, 6, 48, 18, 20, -7, -4, 31])
➞ [31, 32]

BY Python вопросы на собеседовании с ответами


Share with your friend now:
tgoop.com/pythonjuniorjob/817

View MORE
Open in Telegram


Telegram News

Date: |

Members can post their voice notes of themselves screaming. Interestingly, the group doesn’t allow to post anything else which might lead to an instant ban. As of now, there are more than 330 members in the group. The main design elements of your Telegram channel include a name, bio (brief description), and avatar. Your bio should be: A few years ago, you had to use a special bot to run a poll on Telegram. Now you can easily do that yourself in two clicks. Hit the Menu icon and select “Create Poll.” Write your question and add up to 10 options. Running polls is a powerful strategy for getting feedback from your audience. If you’re considering the possibility of modifying your channel in any way, be sure to ask your subscribers’ opinions first. The optimal dimension of the avatar on Telegram is 512px by 512px, and it’s recommended to use PNG format to deliver an unpixelated avatar. More>>
from us


Telegram Python вопросы на собеседовании с ответами
FROM American