I have a list of features selected in the mapcanvas and for those selected features I am doing a buffer and printing the feature names that are inside the buffer. While printing, all values in the list have the same state and cities name. I don't know where I am wrong. I had also attached my code for reference.
layer = iface.activeLayer() selection = layer.selectedFeatures() for feature in selection: buff = feature.geometry().buffer(80467.22489462817, 2) iterFeat = layer.getFeatures() for f in iterFeat: geom2 = f.geometry() valTest = QgsGeometry.within(geom2, buff) if valTest: idx = layer.fieldNameIndex('name') idx1 = layer.fieldNameIndex('state') lsNearCities =  nearCity = feature.attributes()[idx] state = f.attributes()[idx1] state_and_cities = str(state) + "," + nearCity lsNearCities.append(state_and_cities) print lsNearCities