How to align/sort two maps

Does anyone know how to solve this little terraform challenge? I can’t come up with a solution for this. I have two maps like this:

instances = {
“instance1” = “us-east-1a”
“instance2” = “us-east-1a”
“instance3” = “us-east-1c”
“instance4” = “us-east-1b”
“instance5” = “us-east-1b”
“instance6” = “us-east-1c”
}

snapshots = {
“snap1” = “us-east-1c”
“snap2” = “us-east-1b”
“snap3” = “us-east-1b”
“snap4” = “us-east-1c”
“snap5” = “us-east-1a”
“snap6” = “us-east-1a”
}

What I would like to get out of this is:
desired_result = {
“instance1” = “snap5”
“instance2” = “snap6”
“instnace3” = “snap1”
“instance4” = “snap2”
“instance5” = “snap3”
“instance6” = “snap4”
}

Any ideas would be greatly appreciated!

I was finally able to solve this problem. I did a quick writeup on how I did this on stackoverflow in case anyone else runs into a similar issue: https://stackoverflow.com/questions/63735853/how-to-sort-merge-two-maps-in-terraform/63862185

It may not be the cleanest solution, but it accomplishes my goal. If anyone else has suggestions on how to improve the logic or make it more efficient, please do let me know.