我有字典A:
A = {"('All', 'Delhi', 'Mumbai')": {}, "('Container', 'Delhi', 'Mumbai')": {},
"('Open', 'Delhi', 'Mumbai')": {12: [12, 22, 25], 7: [9, 5]},
"('Open', 'Doon', 'Gurgaon')": {10: [1, 2, 24], 8: [4], 9: [28, 8], 7:[21]}}
我想删除所有空字典,该怎么办?
答案 0 :(得分:1)
使用理解力:
>>> {k:v for k,v in A.items() if v}
{"('Open', 'Delhi', 'Mumbai')": {12: [12, 22, 25], 7: [9, 5]}, "('Open', 'Doon', 'Gurgaon')": {10: [1, 2, 24], 8: [4], 9: [28, 8], 7: [21]}}
答案 1 :(得分:0)
您可以在这里使用一种理解:
var range = worksheet.Range("B3:L13");
var objArray = new object[range.ColumnCount(), range.RowCount()];
for (int i = 0; i < range.ColumnCount(); i++)
{
for (int j = 0; j < range.RowCount(); j++)
{
objArray[i, j] = range.Cell(j+1, i+1).Value;
}
}