def remove_values_from_list(the_list, val): return [value for value in the_list if value != val] def remove_consumpton_from_list(the_list, val): return [value for value in the_list if 'keyName' in value and value['keyName'] == 'consumption'] x = [1, 2, 3, 4, 2, 2, 3] x = remove_values_from_list(x, 2) print x # [1, 3, 4, 3] propertyInputs = [{'keyName': 'rando', 'dataValue': 1}, {'keyName': 'notMe', 'dataValue': 2}, {'keyName': 'consumption', 'dataValue': 100}, {'keyName': 'consumption', 'dataValue': 200}] # z = [value for value in y if y['keyName'] != 'consumption'] # print z # [1, 3, 4, 3] for i, propertyInput in propertyInputs: if 'keyName' in propertyInput and propertyInput['keyName'] == 'consumption': print propertyInput else: print "dunno mate" print propertyInputs new_one = [x for x in propertyInputs if 'keyName' in x and x['keyName'] != 'consumption'] print new_one tariffComparisonRequest = { 'groupBy': 'ALL', 'detailLevel': 'RATE', 'billingPeriod': True, 'minimums': True, 'scenarios': [], 'sharedScenario': { 'propertyInputs': [{ 'keyName': 'hasCaliforniaClimateCredit', 'dataValue': False }] } } tariffComparisonRequest['sharedScenario']['propertyInputs'] = [x for x in tariffComparisonRequest['sharedScenario']['propertyInputs'] if 'keyName' in x and x['keyName'] != 'consumption'] print tariffComparisonRequest
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question