Your problem is a little unclear. If the keys are both "foo", you want to print "foo.foo"? or "foofoo"? or do you mean you want the associated values printed? If the latter, how would you tell whether you want A.B or B.A (you give examples of both). Are there any constraints on how you want the output ordered?