0

Here is an example when I were to define one more request initiate_call() ..it should combine all the oututs of the following calls and comebine returns from each and output one final ret. what is the best way to structure this.

def makeA(): 
  return {"name": "steve"}

def makeB(): 
  return {"street": "new York"}

def makeC():
  return {"city": "NY"}

final ret to be like {"name": "steve", "street": "new york", "city": "NY"}

slopeofhope
  • 686
  • 2
  • 6
  • 21
  • 2
    It sounds like you're asking how to immutably merge three dictionaries together? There are multiple dups on that, but the exact answer depends on things like: Does it have to be a `dict`, or would, e.g., a `ChainMap` work? Is there any chance of duplicate keys, and, if so, what do you want to happen? Anyway, there's a canonical question that covers most of the possibilities, so I'll link this as a dup, and if there's some way in which your specific question isn't answered by that, please add a comment, edit your question, and we can reopen it. – abarnert Sep 26 '14 at 23:55
  • Also, is this Python 2 or 3? – abarnert Sep 26 '14 at 23:57
  • Anyway, for 3.x, the short version is probably either `dict(makeA().items() | makeB().items() | makeC().items())` or `dict(collections.ChainMap(makeC(), makeB(), makeA()))`, but you should read all of the answers. – abarnert Sep 27 '14 at 00:00

0 Answers0