originally I had this awful piece of code with two for i in. To sum up, the idea is to get a list of AMI's ID of some AMIS with a particular tag. To do so, I iterate over list (wrong!) and I get a list of IDS.
def aws_get_images_exceptions(connection, exceptions):
list_exceptions = []
for ex in exceptions:
images = connection.get_all_images(filters={ "tag-key":"Name","tag-value":ex})
for ami in images:
list_exceptions.append(ami.id)
return list_exceptions
Over each iteration I get the complete list of "exceptions" based on the fixed tag Role that I provide to function and then I append the right AMIS.
Ok, I was able to remove the second for i in with the next code:
def aws_get_images_exceptions(connection, exceptions):
for ex in exceptions:
images = connection.get_all_images(filters={ "tag-key":"Name","tag-value":ex})
list_exceptions = list(map(lambda x: x.id, images)) + list_exceptions
return list_exceptions
I've checked and I get the same amount of AMIS, same IDS, etc. But I don't get the way to do it in a functional way removing the very first for. As you notice I do a manual call to get_all_images because I iterate over a list of "exceptions" which I give to the function.
Do you know how I can remove this first for i in?
Thanks to all!