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"}
556
I have two Python dictionaries, and I want to write a single expression that returns these two dictionaries, merged (i.e. taking the union).  The update() method would be what I need, if it returned its result instead of modifying a dictionary in-place. &gt;&gt;&gt; x = {'a': 1, 'b': 2} &gt;&gt;&gt; y = {'b': 10, 'c': 11} &gt;&gt;&gt; z = x.update(y) &gt;&gt;&gt; print(z) None &gt;&gt;&gt; x {'a': 1, 'b': 10, 'c': 11}  How can I get that final merged dictionary in z, not x? (To be extra-clear, the last-one-wins conflict-handling of dict.update() is what I'm looking for as well.)
34365
Which style is preferred? Is there a good reason for one vs. the other?  Thanks in advance!  1) cmds.each do |cmd|    end  2) cmds.each { |cmd|    }   Example code:  cmds = [ "create", "update", "list", "help" ]  # Block style one # cmds.each do |cmd|   puts "loop1, cmd: #{cmd}" end  # Block style two # cmds.each { |cmd|   puts "loop2, cmd: #{cmd}" }
43821
I have two JSON objects with the same structure and I want to concat them together using Javascript. Is there an easy way to do this?
110574
So, I want to define a singleton method for an object, but I want to do it using a closure.  For example,  def define_say(obj, msg)   def obj.say     puts msg   end end  o = Object.new define_say o, "hello world!" o.say   This doesn't work because defining a singleton method via "def" is not a closure, so I get an exception that "msg" is an undefined variable or method.  What I would like to do is something like using the "define_method" method in the Module class, but as far as I can tell, this can only be used to define a method on a class... but I want a Singleton Method...  So, I would love to write it something like this:  def define_say(obj, msg)   obj.define_singleton_method(:say) {     puts msg   } end   Does anyone know how I can achieve this without having to create a method to store a Proc and then use the Proc within a singleton method? (basically, I want a clean, non-hacky way of doing this)
103588
In Java, if I call List.toString(), it will automatically call the toString() method on each object inside the List. For example, if my list contains objects o1, o2, and o3, list.toString() would look something like this:  "[" + o1.toString() + ", " + o2.toString() + ", " + o3.toString() + "]"   Is there a way to get similar behavior in Python? I implemented a __str__() method in my class, but when I print out a list of objects, using:  print 'my list is %s'%(list)   it looks something like this:  [&lt;__main__.cell instance at 0x2a955e95f0&gt;, &lt;__main__.cell instance at 0x2a955e9638&gt;, &lt;__main__.cell instance at 0x2a955e9680&gt;]   how can I get python to call my __str__ automatically for each element inside the list (or dict for that matter)?
43162
I have two different @wire methods that are calling Apex methods to get different results from two different objects.  After this information has been retrieved by each @wire respectively, I'd like to afterwards compare the results and set a few other attributes on the page.  How do I achieve this?  Should I use connectedCallback() or renderedCallback() or neither?  Is there a better way to do multiple Apex method calls then process them afterwards within the JS when the component loads?  I'm hoping there's a graceful way to accomplish this in LWC without having to chain Promises, or having to handle all of this within a single Apex method call.
53471
Now that it's clear , there is an associated concept that I use all the time without knowing what it really means.   I suppose everybody made once a mistake with parenthesis, resulting  in an "object is not callable" exception. What's more, using __init__ and __new__ lead to wonder what this bloody __call__ can be used for.  Could you give me some explanations, including examples with the magic method ?
54240
I'm trying to combine a stack data structure with a \newcounter{} definition so that I can automatically pair together a collection of points scattered throughout my text.   Each point is either marked as an \openbracket or a \closebracket, and automatically paired to an oppositely defined point in order to form \openbracket-\closebracket pairs. Closed pairs may be nested within other closed bracket pairs, and each pair of open/closed points are marked with the tikz nodes \node(openX) {}; and \node(closeX) {}; respectively [where X is an integer defined by an external counter].   For example:  \openbraket First tier     \openbraket Second tier A         \openbraket Third tier         \closebracket      \closebracket      \openbracket Second tier B     \closebracket  \closebracket    should automatically pair the above \openbracket \closebracket points into 4 closed bracket pairs; one First tier bracket, containing two Second tier brackets, the first (A) of which contains a single Third tier bracket. My MWE should also pop data from the stack structure so that the tikz nodes in the above example are defined as:   (open0) First tier (open1) Second tier A (open2) Third tier  (close2) (close1) (open3)  Second tier B (close3) (close0)   Using the help of , , and , I have managed to defined a working stack data structure and have figured out a method with which to correctly pass stack data to my \tikzmark macro.   However, the MWE below does not explicitly push the current value of the bracketpairingcounter onto the bracketpairingstack, and pushes the verbatim command string instead of the required integer number. Thus when each \node(closeX) {}; tikz mark is popped from the data stack, each node number is evaluated at the last value of bracketpairingcounter, instead of the different integers sequentially pushed onto the stack.   I'm hoping that the numbering problem can be fixed by somehow forcing my LaTeX code to immediately evaluate the value of \openbracketname below, but I can't for the life of me get \expandafter or \edef{} to work in this case...   MWE  \documentclass[openany]{article} \usepackage{tikz}  %Define stack data structure commands (\push, \pop, \splitstack) \newtoks\braketpairingstack \braketpairingstack={\empty}      \def\push#1#2{%         \def\tmp{{#1}}%          \expandafter\expandafter\expandafter%         #2\expandafter\expandafter\expandafter{\expandafter\tmp\the#2}%     \ignorespaces}      \def\pop#1#2{%         \expandafter\splitstack\the#1\stop{#1}{#2}%     }      \def\splitstack#1#2\stop#3#4{%          \def\tmp{#1}         \ifx\tmp\empty          \else             \def#4{#1}\global#3={#2}%         \fi     }   %Define \tikzmark command \def\tikzmark#1{%     \tikz[remember picture, overlay]\node[red](#1) {#1};% }  %Define bracket pair counting commands (\openbracket, \closebracket) \newcounter{bracketpairingcounter}      \newcommand{\openbraket}{%         \expandafter\edef\csname openbracketname\endcsname{\thebracketpairingcounter}%         \push{\openbracketname}{\braketpairingstack}%         \tikzmark{open\openbracketname}%         \stepcounter{bracketpairingcounter}%     }      \newcommand{\closebraket}{%         \pop{\braketpairingstack}{\closebracketname}%         \tikzmark{close\closebracketname}%     }  %Begin MWE document \begin{document}     \openbraket Open first bracket.\\ %Correctly marked as open0     \openbraket Open second bracket.\\ %Correctly marked as open1      Close second bracket. \closebraket\\ %Correctly marked as close1      Close first bracket. \closebraket\\ %Incorrectly marked as close1 \end{document}
29728
In other words, can I do something like  for() {     for {        for {        }     } }   Except N times? In other words, when the method creating the loops is called, it is given some parameter N, and the method would then create N of these loops nested one in another?  Of course, the idea is that there should be an "easy" or "the usual" way of doing it. I already have an idea for a very complicated one.
43386
Is there a more concise way of doing this in Python?:  def toDict(keys, values):   d = dict()   for k,v in zip(keys, values):     d[k] = v    return d
107627
Is it the same convention as those used in known programming languages such as Java and C? I'm trying to create a lot of variables and I want it to start with a number, but I'm not sure if it's okay.
111110
I'm a bit confused as to how to get two method to call each other (i.e., have A() call B() and B() call A()). It seems that F# only 'sees' the method after it's been encountered in code, so if it hasn't, it just says value or constructor has not been defined.  Am I missing something very basic here?
76755
I have a bit of code where I've written a SOQL query that returns a list of SObject records, however I need a Set&lt;Id&gt; structure to pass to another method that I don't have control of (and thus can't change the method signature of).  How can I turn my returned List&lt;SObject&gt; into a Set&lt;Id&gt;? Is the best option just a for loop?
37679
I'm calling a function in Python which I know may stall and force me to restart the script.   How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else?
67149
I'm trying to create an array of arrays that will be using repeated data, something like below:  int[] list1 = new int[4] { 1, 2, 3, 4 }; int[] list2 = new int[4] { 5, 6, 7, 8 }; int[] list3 = new int[4] { 1, 3, 2, 1 }; int[] list4 = new int[4] { 5, 4, 3, 2 };  int[,] lists = new int[4, 4] {  list1 ,  list2 ,  list3 ,  list4  };   I can't get it to work and so I'm wondering if I'm approaching this wrong.   What I'm attempting to do is create some sort of method to create a long list of the values so I can process them in a specific order, repeatedly. Something like,  int[,] lists = new int[90,4] { list1, list1, list3, list1, list2, (and so on)};  for (int i = 0; i &lt; 90; ++i) {    doStuff(lists[i]); }   and have the arrays passed to doStuff() in order. Am I going about this entirely wrong, or am I missing something for creating the array of arrays?
94067
I can't find a definitive answer for this. As far as I know, you can't have multiple __init__ functions in a Python class. So how do I solve this problem? Suppose I have a class called Cheese with the number_of_holes property. How can I have two ways of creating cheese objects...  One that takes a number of holes like this: parmesan = Cheese(num_holes = 15) And one that takes no arguments and just randomizes the number_of_holes property: gouda = Cheese()  I can think of only one way to do this, but this seems clunky: class Cheese():     def __init__(self, num_holes = 0):         if (num_holes == 0):             # Randomize number_of_holes         else:             number_of_holes = num_holes  What do you say? Is there another way?
18599
I want to return two objects from a Java method and was wondering what could be a good way of doing so?  The possible ways I can think of are: return a HashMap (since the two Objects are related) or return an ArrayList of Object objects.  To be more precise, the two objects I want to return are (a) List of objects and (b) comma separated names of the same.  I want to return these two Objects from one method because I dont want to iterate through the list of objects to get the comma separated names (which I can do in the same loop in this method).  Somehow, returning a HashMap does not look a very elegant way of doing so.