Even and Odd Groups
Grouping helps you sort data into simple, useful buckets. The function group_by_parity receives a list of numbers nums and separates them into even and odd numbers. Return a dictionary with the keys even and odd, and keep the numbers inside each list in their original order of appearance.
Примеры
Ввод
[1, 2, 3, 4]Вывод
{"even": [2, 4], "odd": [1, 3]}Ввод
[]Вывод
{"even": [], "odd": []}Ввод
[2, 4, 6]Вывод
{"even": [2, 4, 6], "odd": []}Нужно реализовать
def group_by_parity(nums: list[int]) -> dict:
Теги
listsdict
Pieslēdzies, lai redzētu iesniegumu vēsturi
PieslēgtiesPieslēdzies, lai izmantotu AI mentoru
PieslēgtiesTests12
Visible tests
Slēptais tests 7
Slēptais tests 8
Slēptais tests 9
Slēptais tests 10
Slēptais tests 11
Slēptais tests 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid