I have a function number_sort() which needs to return a 2d list with 4 lists inside. Function needs to sort the numbers given by being between 0-12, 13-25, 26-38 and 39-51 which looks like:
Given: [2, 2, 3, 4, 1, 13, 15, 51, 10, 15, 28]
Returned: [[1, 2, 2, 3, 4, 10], [13, 15, 15], [28], [51]]
I tried doing it with list comprehension.
def number_sort(cards: list):
return [[item for item in cards if i * 13 <= item <= (i * 12 + 1)] for i in range(4)]
But when I give the exact example list given above, It returns [[1], [13], [], []]
Can someone tell me what am I doing wrong and how can I fix it?