Создайте комбинированные наборы всех ключей со всеми значениями LDICT
и вычтите их из набора LS
:
(длинный путь)
LDICT = [ {i:"" for i in range(k,k+20,3)} for k in range(0,100,20)]
LS = [x for x in range(100) if x%4 == 0]
print(LDICT)
print(LS)
all_keys = set(x for d in LDICT for x in d)
print(all_keys)
cleaned_keys = set(LS)-all_keys
print(cleaned_keys)
Вывод:
# LDICT
[{0: '', 3: '', 6: '', 9: '', 12: '', 15: '', 18: ''},
{20: '', 23: '', 26: '', 29: '', 32: '', 35: '', 38: ''},
{40: '', 43: '', 46: '', 49: '', 52: '', 55: '', 58: ''},
{60: '', 63: '', 66: '', 69: '', 72: '', 75: '', 78: ''},
{80: '', 83: '', 86: '', 89: '', 92: '', 95: '', 98: ''}]
# LS
[0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64,
68, 72, 76, 80, 84, 88, 92, 96]
# all_keys
{0, 3, 6, 9, 12, 15, 18, 20, 23, 26, 29, 32, 35, 38, 40, 43, 46, 49, 52, 55, 58, 60,
63, 66, 69, 72, 75, 78, 80, 83, 86, 89, 92, 95, 98}
# cleaned_keys
{64, 96, 4, 36, 68, 8, 44, 76, 16, 48, 84, 24, 56, 88, 28}
Вам просто нужно составить список из cleaned_keys
.
Доку: