Вы также можете сравнить окно с чистой версией окна, а не пытаться сделать снимок во время выполнения для сравнения. Я запускал это в консоли, но вы можете превратить его в функцию.
// make sure it doesn't count my own properties
(function () {
var results, currentWindow,
// create an iframe and append to body to load a clean window object
iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
// filter the list against the properties that exist in the clean window
results = currentWindow.filter(function(prop) {
return !iframe.contentWindow.hasOwnProperty(prop);
});
// log an array of properties that are different
console.log(results);
document.body.removeChild(iframe);
}());
Если я понял вашу логику, вот мое решение:
#method to create samples list
nb_s = 3;nb_d = 2
S = ['s' + str(x) for x in range(1, nb_s + 1)]
D = ['d' + str(x) for x in range(1, nb_d + 1)]
C = ['c' + str(x) for x in range(1, (len(S) * len(D)) + 1)]
print(S);print(D);print(C)
dico_s = {}
for s in S:
dico_d = {}
for d in D:
idx = D.index(d) + len(D) * S.index(s)
dico_d[d] = C[idx]
dico_s[s] = dico_d
print(dico_s)
вывод:
S ->['s1', 's2', 's3']
D ->['d1', 'd2']
C->['c1', 'c2', 'c3', 'c4', 'c5', 'c6']
DICO->{'s1': {'d1': 'c1', 'd2': 'c2'},
's2': {'d1': 'c3', 'd2': 'c4'},
's3': {'d1': 'c5', 'd2': 'c6'}}
--------------------------
**for nb_s = 4 and nb_d = 6**
S -> ['s1', 's2', 's3', 's4']
D -> ['d1', 'd2', 'd3', 'd4', 'd5', 'd6']
C -> ['c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10', 'c11', 'c12',
'c13', 'c14', 'c15', 'c16', 'c17', 'c18', 'c19', 'c20', 'c21', 'c22', 'c23', 'c24']
DICO -> {'s1': {'d1': 'c1', 'd2': 'c2', 'd3': 'c3', 'd4': 'c4', 'd5': 'c5', 'd6': 'c6'},
's2': {'d1': 'c7', 'd2': 'c8', 'd3': 'c9', 'd4': 'c10', 'd5': 'c11', 'd6': 'c12'},
's3': {'d1': 'c13', 'd2': 'c14', 'd3': 'c15', 'd4': 'c16', 'd5': 'c17', 'd6': 'c18'},
's4': {'d1': 'c19', 'd2': 'c20', 'd3': 'c21', 'd4': 'c22', 'd5': 'c23', 'd6': 'c24'}}