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
PostgreSQLv16

Siia ilmub koodi käivituse tulemus

Visible tests
1
Input
[1,2,3,4]
Expected{"odd":[1,3],"even":[2,4]}
2
Input
[]
Expected{"odd":[],"even":[]}
3
Input
[2,4,6]
Expected{"odd":[],"even":[2,4,6]}
4
Input
[1,3]
Expected{"odd":[1,3],"even":[]}
5
Input
[0]
Expected{"odd":[],"even":[0]}
6
Input
[2,3,4,5]
Expected{"odd":[3,5],"even":[2,4]}
Focus radio
Paused · SomaFM · Fluid