I declare a python dictionary like this using double quotes;  {     "Name":"John",     "Date":"2/18/1998",     "Profit":25.12 }   The same python dictionary can be written like this using single quotes;  {     'Name':'John',     'Date':'2/18/1998',     'Profit':25.12 }   What is the difference, if any, between the two? What is the best practice in python? Practical-wise, I encounter no difference so far. I'm not sure if I missed out anything.
3288
According to the documentation, they're pretty much interchangeable.  Is there a stylistic reason to use one over the other?
39591
I have nested dictionaries:  {'key0': {'attrs': {'entity': 'p', 'hash': '34nj3h43b4n3', 'id': '4130'},           u'key1': {'attrs': {'entity': 'r',                               'hash': '34njasd3h43b4n3',                               'id': '4130-1'},                     u'key2': {'attrs': {'entity': 'c',                                         'hash': '34njasd3h43bdsfsd4n3',                                         'id': '4130-1-1'}}},           u'key3': {'attrs': {'entity': 'r',                               'hash': '34njasasasd3h43b4n3',                               'id': '4130-2'},                     u'key4': {'attrs': {'entity': 'c',                                         'hash': '34njawersd3h43bdsfsd4n3',                                         'id': '4130-2-1'}},                     u'key5': {'attrs': {'entity': 'c',                                         'hash': '34njawersd3h43bdsfsd4n3',                                         'id': '4130-2-2'}}}},  'someohterthing': 'someothervalue',  'something': 'somevalue'}   given an id  - one of all the ids like 4130 to 4130-2-2.                       whats the easiest way to navigate to the correct dictionary?  Like if the given id is 4130-2-1 then it should reach the dictionary with key=key5  non xml approaches please.  Edit(1): The nesting is between 1 to 4 levels, but I know the nesting before I parse.  Edit(2): Fixed the code.  **Edit(3):**Fixed code again for string values of ids. Please excuse for the confusion created. This is final I hope :)
91496
Something's been bugging me about SO for a while now, that is the inaccuracy of "length of time" strings.  The best example I can give at the moment is .  If you look at the length of time he's been registered, it says 1 year.  He joined the site September 2008, which is only 3 months off two years.  It's the same with answers - you can give an answer 50 seconds before anyone else, but at certain times page views will show both as "5 minutes ago" or whatever.  That's not quite as bad, but with answers being sorted "randomly by votes" by default you could lose out on votes or being marked as the correct answer to the slower answer even if they're both the same.  There's probably a better method amongst these, IMO:   "Vulgar fraction" unicode characters     Member for 1½ years   answered 5¼ minutes ago asked 3⅓ hours ago  Different units   Member for 21 months (at least it's better than "1 year") Answered 306 seconds ago (ugly, I know) Asked 64 minutes ago (also ugly)  Combining units   Member for 1 year 9 months (fits easily on the profile screen) Answered 5 minutes 6 seconds ago (probably too long) Asked 3 hours 20 minutes ago (also long)  Rounding up   I personally prefer option 1, unicode fraction characters.  "Member for 21 months" is pretty good too because it's easy to quickly work out.  "Asked 452 seconds" ago is horrible though.  EDIT: I'm completely aware of the timestamp hover because I am forced into using it so much. It's a great feature, but it's not really in your face so not everyone knows about it. I still think there's a better "glancing" solution than having to hover over the time string.
85430
Here's a silly fun question:  Let's say we have to perform a simple operation where we need half of the value of a variable. There are typically two ways of doing this:  y = x / 2.0; // or... y = x * 0.5;   Assuming we're using the standard operators provided with the language, which one has better performance?  I'm guessing multiplication is typically better so I try to stick to that when I code, but I would like to confirm this.   Although personally I'm interested in the answer for Python 2.4-2.5, feel free to also post an answer for other languages! And if you'd like, feel free to post other fancier ways (like using bitwise shift operators) as well.
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.)
13157
Let's say that you want to output or concat strings. Which of the following styles do you prefer?   var p = new { FirstName = "Bill", LastName = "Gates" }; Console.WriteLine("{0} {1}", p.FirstName, p.LastName); Console.WriteLine(p.FirstName + " " + p.LastName);   Do you rather use format or do you simply concat strings? What is your favorite? Is one of these hurting your eyes?  Do you have any rational arguments to use one and not the other?  I'd go for the second one.
17421
A friend of mine, native EN speaker, told me that the following is correct written like this:      We met on the 1st of June.   Is that really true? I cannot see any reference that these are used in written text.
31399
This is my code:  import datetime today = datetime.date.today() print(today)   This prints: 2008-11-22 which is exactly what I want.  But, I have a list I'm appending this to and then suddenly everything goes "wonky". Here is the code:  import datetime mylist = [] today = datetime.date.today() mylist.append(today) print(mylist)   This prints the following:   [datetime.date(2008, 11, 22)]   How can I get just a simple date like 2008-11-22?
115925
Is there any difference between:  if foo is None: pass   and  if foo == None: pass   The convention that I've seen in most Python code (and the code I myself write) is the former, but I recently came across code which uses the latter.  None is an instance (and the only instance, IIRC) of NoneType, so it shouldn't matter, right?  Are there any circumstances in which it might?
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
113875
I have 4 fields with Date Time values, and created a new field (Date type as well) which takes the most recent date from these 4 fields. I have tried using the Max python in the field calculator to populate this new field, but it does not use the most recent date from these 4 fields. Does this function not work with Datetime values, or is there another function for this that I am not able to find on these forums.   max([!field1!, !field2!, !field3!, !field4!])   I am on 10.5.  When I have two fields that have a date within the same month, it will not read the rest of the date correctly. (See picture attached)    When I run the following updated code it fails and says it is a syntax error.      With the current code, it reads the first number in the day to select the most recent date. (As shown below). It does not use the correct chronological format, even though the strptime format worked previously.
48764
Does anyone know how the built in dictionary type for python is implemented?  My understanding is that it is some sort of hash table, but I haven't been able to find any sort of definitive answer.
93053
(assume php5) consider  &lt;?php      $foo = 'some words';      //case 1     print "these are $foo";      //case 2     print "these are {$foo}";      //case 3     print 'these are ' . $foo; ?&gt;   Is there much of a difference between 1 and 2?  If not, what about between 1/2 and 3?
57923
I wanted to use this, but I don't know if it's actually valid in English:     The specified date is invalid.It points to a non-existing day.   I'm not a native speaker, and I just want to say that the input points to a date that does not exist, like 30th February.
60856
I have a string that looks like this:  "Name1=Value1;Name2=Value2;Name3=Value3"   Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this:  dict = {     "Name1": "Value1",     "Name2": "Value2",     "Name3": "Value3" }   I have looked through the modules available but can't seem to find anything that matches.    Thanks, I do know how to make the relevant code myself, but since such smallish solutions are usually mine-fields waiting to happen (ie. someone writes: Name1='Value1=2';) etc. then I usually prefer some pre-tested function.  I'll do it myself then.
75387
Suppose I have a particular date stored in a variable date_m. I want ((date_m)-25) date.   For example: I have 15/09/2014 stored in my variable , then I want 21/08/2014 returned if I subtract 25 from the date stored in variable.
4570
I'd like to call a function in python using a dictionary.  Here is some code:  d = dict(param='test')  def f(param):     print(param)  f(d)   This prints {'param': 'test'} but I'd like it to just print test.  I'd like it to work similarly for more parameters:  d = dict(p1=1, p2=2) def f2(p1, p2):     print(p1, p2) f2(d)   Is this possible?