无法从python lis中删除元素

2024-09-27 00:18:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一份词典目录

[{
    'Questions': [{
      'Question': '<P>The dimensions of angle of contact is:',
      'QuestionInd': 3,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': 'M<SUP>0</SUP>L<SUP>1</SUP>T<SUP>0</SUP>',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': 'M<SUP>1</SUP>L<SUP>0</SUP>T<SUP>0</SUP>',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': 'M<SUP>0</SUP>L<SUP>0</SUP>T<SUP>0</SUP>',
        'IsCorrect': 'true'
      }, {
        'OptInd': 4,
        'Options': 'M<SUP>0</SUP>L<SUP>1</SUP>T<SUP>1</SUP>',
        'IsCorrect': 'false'
      }]
    }, {
      'Question': '<P>Dimensions of ratio of momentum &amp; impulse is:-',
      'QuestionInd': 4,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': 'M<SUP>1</SUP>L<SUP>1</SUP>T<SUP>_1</SUP>',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': 'M<SUP>1</SUP>L<SUP>1</SUP>T<SUP>_2</SUP>',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': 'M<SUP>2</SUP>L<SUP>1</SUP>T<SUP>_1</SUP>',
        'IsCorrect': 'false'
      }, {
        'OptInd': 4,
        'Options': 'M<SUP>0</SUP>L<SUP>0</SUP>T<SUP>0',
        'IsCorrect': 'true'
      }]
    }, {
      'Question': '<P>The expression [ML<SUP>&minus;1</SUP>T<SUP>&minus;1</SUP>] represents',
      'QuestionInd': 8,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': 'momentum',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': 'force',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': 'pressure',
        'IsCorrect': 'false'
      }, {
        'OptInd': 4,
        'Options': 'coefficient of viscosity',
        'IsCorrect': 'true'
      }]
    }],
    'SectionInd': 1,
    'Section': 'Physics',
    'SectionTotalQuestion': 3,
    'color': '',
    'errorExists': 'false',
    'isValidOrInvalidCheckForSection': 'true',
    'SectionTotalMarks': 12,
    'SectionTotalTime': 3600
  }, {
    'Questions': [{
      'Question': '<P>Van\'t Hoff factor of <IMG class=img-align SRC="ckfinder/userfiles/images/Motion_Practice_Chemistry_Question_2019-1-2_Batch-11_V2/MoWMF861.JPG" WIDTH="56" HEIGHT="18" \r\nALIGN="BOTTOM"> is',
      'QuestionInd': 1,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': '1',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': '2',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': '3',
        'IsCorrect': 'true'
      }, {
        'OptInd': 4,
        'Options': '4',
        'IsCorrect': 'false'
      }]
    }, {
      'Question': '<P>25 mL of 3 M HCl were added to 75 mL of 0.05 M HCl. The molarity of HCl in the resulting solution   &emsp;&emsp;&emsp;&emsp;   \r\n   &emsp;&emsp;&emsp;&emsp;  is approximately-',
      'QuestionInd': 2,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': '0.055 M',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': '0.35 M',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': '0.787 M',
        'IsCorrect': 'true'
      }, {
        'OptInd': 4,
        'Options': '3.05 M',
        'IsCorrect': 'false'
      }]
    }, {
      'Question': '<P>At 300 K, the vapour pressure of an ideal solution containing one mole of A and 3 moles of B is 550 mm \r\nof Hg. At the same temperature, if one mole of B is added to this solution, the vapour pressure of \r\nsolution increases by 10mm of Hg. Calculate the vapour pressure of A and B in their pure state.',
      'QuestionInd': 5,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': '400 mm, 600 mm',
        'IsCorrect': 'true'
      }, {
        'OptInd': 2,
        'Options': '600 mm, 400 mm',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': '200 mm, 300 mm',
        'IsCorrect': 'false'
      }, {
        'OptInd': 4,
        'Options': '300 mm, 200 mm',
        'IsCorrect': 'false'
      }]
    }, {
      'Question': '<P>Which of the following conditions is not correct for ideal solution-',
      'QuestionInd': 6,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': 'no change in volume on mixing',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': 'no change in enthalpy on mixing',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': "it obeys Raoult's law",
        'IsCorrect': 'false'
      }, {
        'OptInd': 4,
        'Options': 'Ionisation of solute should occurs to a small extent',
        'IsCorrect': 'true'
      }]
    }],
    'SectionInd': 2,
    'Section': 'Chemistry',
    'SectionTotalQuestion': 4,
    'color': '',
    'errorExists': 'false',
    'isValidOrInvalidCheckForSection': 'true',
    'SectionTotalMarks': 16,
    'SectionTotalTime': 3600
  }, {
    'Questions': [{
      'Question': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p>The product of the roots of equation</p>\n<math><msup><mrow><mi mathvariant="normal">x</mi></mrow><mrow><msub><mrow><mi mathvariant="normal">log</mi></mrow><mrow><mn>10</mn></mrow></msub><mi mathvariant="normal">x</mi></mrow></msup><mo>=</mo><mfrac><mrow><msup><mrow><mn>10</mn></mrow><mrow><mn>4</mn></mrow></msup></mrow><mrow><msup><mrow><mi mathvariant="normal">x</mi></mrow><mrow><mn>3</mn></mrow></msup></mrow></mfrac><mo>,</mo><mi mathvariant="normal"> is</mi></math></body>\n</html>',
      'QuestionInd': 7,
      'QuestionMaxMarks': '4',
      'QuestionNegativeMarks': '0',
      'isMultipleOrSingle': 'multiple',
      'QuestionTagList': [],
      'Options': [{
        'OptInd': 1,
        'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{10}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B10%7D" /></p>\n</body>\n</html>\n',
        'IsCorrect': 'false'
      }, {
        'OptInd': 2,
        'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{100}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B100%7D" /></p>\n</body>\n</html>\n',
        'IsCorrect': 'false'
      }, {
        'OptInd': 3,
        'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{1000}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B1000%7D" /></p>\n</body>\n</html>\n',
        'IsCorrect': 'true'
      }, {
        'OptInd': 4,
        'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{10000}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B10000%7D" /></p>\n</body>\n</html>\n',
        'IsCorrect': 'false'
      }]
    }],
    'SectionInd': 3,
    'Section': 'Maths',
    'SectionTotalQuestion': 1,
    'color': '',
    'errorExists': 'false',
    'isValidOrInvalidCheckForSection': 'true',
    'SectionTotalMarks': 4,
    'SectionTotalTime': 3600
  }, {
    'Questions': [],
    'SectionInd': 4,
    'Section': 'Biology',
    'SectionTotalQuestion': 0,
    'color': '',
    'errorExists': 'false',
    'isValidOrInvalidCheckForSection': 'true',
    'SectionTotalMarks': 0,
    'SectionTotalTime': 3600
  }, {
    'Questions': [],
    'SectionInd': 5,
    'Section': 'GK',
    'SectionTotalQuestion': 0,
    'color': '',
    'errorExists': 'false',
    'isValidOrInvalidCheckForSection': 'true',
    'SectionTotalMarks': 0,
    'SectionTotalTime': 3
  }
}]

我想删除具有键值对SectionTotalQ的元素uestion:0 这是我用来删除元素的代码

for i in section_infor:
  if i['SectionTotalQuestion']==0:
      section_infor.remove(i)

这就是我得到的结果

[{
  'Questions': [{
    'Question': '<P>The dimensions of angle of contact is:',
    'QuestionInd': 3,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': 'M<SUP>0</SUP>L<SUP>1</SUP>T<SUP>0</SUP>',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': 'M<SUP>1</SUP>L<SUP>0</SUP>T<SUP>0</SUP>',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': 'M<SUP>0</SUP>L<SUP>0</SUP>T<SUP>0</SUP>',
      'IsCorrect': 'true'
    }, {
      'OptInd': 4,
      'Options': 'M<SUP>0</SUP>L<SUP>1</SUP>T<SUP>1</SUP>',
      'IsCorrect': 'false'
    }]
  }, {
    'Question': '<P>Dimensions of ratio of momentum &amp; impulse is:-',
    'QuestionInd': 4,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': 'M<SUP>1</SUP>L<SUP>1</SUP>T<SUP>_1</SUP>',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': 'M<SUP>1</SUP>L<SUP>1</SUP>T<SUP>_2</SUP>',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': 'M<SUP>2</SUP>L<SUP>1</SUP>T<SUP>_1</SUP>',
      'IsCorrect': 'false'
    }, {
      'OptInd': 4,
      'Options': 'M<SUP>0</SUP>L<SUP>0</SUP>T<SUP>0',
      'IsCorrect': 'true'
    }]
  }, {
    'Question': '<P>The expression [ML<SUP>&minus;1</SUP>T<SUP>&minus;1</SUP>] represents',
    'QuestionInd': 8,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': 'momentum',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': 'force',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': 'pressure',
      'IsCorrect': 'false'
    }, {
      'OptInd': 4,
      'Options': 'coefficient of viscosity',
      'IsCorrect': 'true'
    }]
  }],
  'SectionInd': 1,
  'Section': 'Physics',
  'SectionTotalQuestion': 3,
  'color': '',
  'errorExists': 'false',
  'isValidOrInvalidCheckForSection': 'true',
  'SectionTotalMarks': 12,
  'SectionTotalTime': 3600
}, {
  'Questions': [{
    'Question': '<P>Van\'t Hoff factor of <IMG class=img-align SRC="ckfinder/userfiles/images/Motion_Practice_Chemistry_Question_2019-1-2_Batch-11_V2/MoWMF861.JPG" WIDTH="56" HEIGHT="18" \r\nALIGN="BOTTOM"> is',
    'QuestionInd': 1,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': '1',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': '2',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': '3',
      'IsCorrect': 'true'
    }, {
      'OptInd': 4,
      'Options': '4',
      'IsCorrect': 'false'
    }]
  }, {
    'Question': '<P>25 mL of 3 M HCl were added to 75 mL of 0.05 M HCl. The molarity of HCl in the resulting solution   &emsp;&emsp;&emsp;&emsp;   \r\n   &emsp;&emsp;&emsp;&emsp;  is approximately-',
    'QuestionInd': 2,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': '0.055 M',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': '0.35 M',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': '0.787 M',
      'IsCorrect': 'true'
    }, {
      'OptInd': 4,
      'Options': '3.05 M',
      'IsCorrect': 'false'
    }]
  }, {
    'Question': '<P>At 300 K, the vapour pressure of an ideal solution containing one mole of A and 3 moles of B is 550 mm \r\nof Hg. At the same temperature, if one mole of B is added to this solution, the vapour pressure of \r\nsolution increases by 10mm of Hg. Calculate the vapour pressure of A and B in their pure state.',
    'QuestionInd': 5,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': '400 mm, 600 mm',
      'IsCorrect': 'true'
    }, {
      'OptInd': 2,
      'Options': '600 mm, 400 mm',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': '200 mm, 300 mm',
      'IsCorrect': 'false'
    }, {
      'OptInd': 4,
      'Options': '300 mm, 200 mm',
      'IsCorrect': 'false'
    }]
  }, {
    'Question': '<P>Which of the following conditions is not correct for ideal solution-',
    'QuestionInd': 6,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': 'no change in volume on mixing',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': 'no change in enthalpy on mixing',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': "it obeys Raoult's law",
      'IsCorrect': 'false'
    }, {
      'OptInd': 4,
      'Options': 'Ionisation of solute should occurs to a small extent',
      'IsCorrect': 'true'
    }]
  }],
  'SectionInd': 2,
  'Section': 'Chemistry',
  'SectionTotalQuestion': 4,
  'color': '',
  'errorExists': 'false',
  'isValidOrInvalidCheckForSection': 'true',
  'SectionTotalMarks': 16,
  'SectionTotalTime': 3600
}, {
  'Questions': [{
    'Question': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p>The product of the roots of equation</p>\n<math><msup><mrow><mi mathvariant="normal">x</mi></mrow><mrow><msub><mrow><mi mathvariant="normal">log</mi></mrow><mrow><mn>10</mn></mrow></msub><mi mathvariant="normal">x</mi></mrow></msup><mo>=</mo><mfrac><mrow><msup><mrow><mn>10</mn></mrow><mrow><mn>4</mn></mrow></msup></mrow><mrow><msup><mrow><mi mathvariant="normal">x</mi></mrow><mrow><mn>3</mn></mrow></msup></mrow></mfrac><mo>,</mo><mi mathvariant="normal"> is</mi></math></body>\n</html>',
    'QuestionInd': 7,
    'QuestionMaxMarks': '4',
    'QuestionNegativeMarks': '0',
    'isMultipleOrSingle': 'multiple',
    'QuestionTagList': [],
    'Options': [{
      'OptInd': 1,
      'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{10}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B10%7D" /></p>\n</body>\n</html>\n',
      'IsCorrect': 'false'
    }, {
      'OptInd': 2,
      'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{100}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B100%7D" /></p>\n</body>\n</html>\n',
      'IsCorrect': 'false'
    }, {
      'OptInd': 3,
      'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{1000}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B1000%7D" /></p>\n</body>\n</html>\n',
      'IsCorrect': 'true'
    }, {
      'OptInd': 4,
      'Options': '<html>\n<head>\n\t<title></title>\n</head>\n<body>\n<p><img alt="\\frac{1}{10000}" src="http://latex.codecogs.com/gif.latex?%5Cfrac%7B1%7D%7B10000%7D" /></p>\n</body>\n</html>\n',
      'IsCorrect': 'false'
    }]
  }],
  'SectionInd': 3,
  'Section': 'Maths',
  'SectionTotalQuestion': 1,
  'color': '',
  'errorExists': 'false',
  'isValidOrInvalidCheckForSection': 'true',
  'SectionTotalMarks': 4,
  'SectionTotalTime': 3600
}, {
  'Questions': [],
  'SectionInd': 5,
  'Section': 'GK',
  'SectionTotalQuestion': 0,
  'color': '',
  'errorExists': 'false',
  'isValidOrInvalidCheckForSection': 'true',
  'SectionTotalMarks': 0,
  'SectionTotalTime': 3600
}]

值为0的key SectionTotalQuestion的所有元素都将从最后一个元素中删除。原因是什么?我该如何解决


Tags: offalsetruetitlehtmlbodyheadsup

热门问题