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