#!/usr/local/bin/python3 x = [1, 2, 3, 4, 5, 6, 7, 8] y = {} for n in x: p = n % 3 y.setdefault(p, []).append(n) print(y)