You just need to have the list of instances that you want to delete and then pass it as an argument and you are done.
you can use the following code for the same:
import boto3
ids = ['i-1','i-2','i-3','i-4','i-5']
ec2 = boto3.resource('ec2')
ec2.instances.filter(InstanceIds = ids).terminate()
This will serve the purpose. Hope this helps.