<html><body><div><br></div><div><br>On Apr 28, 2014, at 12:36 PM, Ned Batchelder <ned@nedbatchelder.com> wrote:<br><br><div><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span style="white-space:pre;" data-mce-style="white-space: pre;">On 4/27/14 5:51 PM, Andrew Konstantaras wrote:<br>        > I guess I am missing something big as I am looking for a shorthand way<br>        > of doing the following:<br>        ><br>        > dctA = dict(x=x, y=y, ... n=n)<br>        ><br><br>Yes, your makeDict(x, y) is a shorthand for dict(x=x, y=y), but there <br>are many things you can do with dict that you can't do with makeDict. <br>What is the makeDict equivalent of:<br><br> dict(x=12, y=self.y, z=a+b)<br><br>The code you have allows you more compact expression, but it brings <br>fragility and surprise.<br><br>        > This is, as I understand it a very natural way of using a dictionary.<br>        > It seems that this syntax is unnecessarily redundant and hence my goal<br>        > of writing something more compact. Perhaps the way I am doing it is a<br>        > little unorthodox, but the ultimate use of a dictionary is, as I<br>        > understand it, completely in line with how dictionaries were designed to<br>        > be used. In my other code, I often use these dictionaries to pass<br>        > arguments to functions and return results. It allows me great<br>        > flexibility without breaking existing code. I pack a dictionary before<br>        > passing and unpack when retrieving.<br><br>Perhaps you want to create a class instead? If you find yourself <br>passing more than a handful of arguments to a function, and especially <br>more than a handful of values returned from a function, then a class <br>with methods might be a better way to combine state and behavior.<br><br>Also, keep in mind that you can return a tuple from a function if you <br>want to return two or three values and assign them to names:<br><br> x, y, z = compute_xyz()<br><br>You mention unpacking your dictionary after the function call. How do <br>you do that? Isn't that a cumbersome and repetitive operation?<br></span></div></div></blockquote><span>One of the reasons I like using the dictionary over the tuple is that if I have a function that grows in functionality (i.e., I decide to return more data for new scenarios), I can just add the new object to the dictionary and I don't have to worry about changing the code every where else that used to call the function.  <br> </span><br>Actually, that is one of the nice features of using a dictionary, I can check if the key is there and if it is pull it out.  As I was dusting off this old code, I considered trying to implement this functionality through by creating a class.  I never liked going through the stack, it seemed hacky, but I came to love using dictionaries as they have some great built in features.  <br><br>Again, thanks for the advice and I will focus on the class implementation.<br><br><blockquote type="cite"><div class="msg-quote"><div class="_stretch"><span style="white-space:pre;" data-mce-style="white-space: pre;"><br>        ><br>        > I will give the locals approach a try, it seems a little more clumsy<br>        > than simply passing the variables to the function.<br>        ><br>        > Thanks again for your input.<br>        ><br>        > ---Andrew<br><br>BTW, it's a little easier to follow the threads of conversation if you <br>put your responses after the text you are responding to. This is known <br>as bottom-posting, and is preferred to top-posting as you did here.<br><br><br>-- <br>Ned Batchelder, <a href="http://nedbatchelder.com" data-mce-href="http://nedbatchelder.com">http://nedbatchelder.com</a><br><br>-- <br><a href="https://mail.python.org/mailman/listinfo/python-list" data-mce-href="https://mail.python.org/mailman/listinfo/python-list">https://mail.python.org/mailman/listinfo/python-list</a><br></span></div></div></blockquote></div></div></body></html>