In QGIS 2.18 I'm try to sort features by an integer attribute with a Python script. The problem is, that some of the values of the sorting attribue are <= 0 (for sure they have to be <=0) and these features are ignorded in the sorting. How do I have to change the syntax to be sure, that also features with attribute [1] <= 0 are placed on the very first places of the table?
for feature in layer.getFeatures():
count = layer.featureCount()
geom = feature.geometry()
attr = feature.attributes()
features = sorted(layer.getFeatures(),key = lambda feature: feature[1])
layer_provider = layer.dataProvider()
layer_provider.addFeatures(features)
layer.commitChanges()