There are two dictionaries (d1 and d2) formed after combining list values. I have to subtract the values (d2-d1) and print the dictionary. d1 = {'Rash': '80000000', 'Kil': '80000020', 'Varsha': '80000020', 'sam': '80010000'}   d2 = {'Varsha': '8000ffe0', 'sam': '80014000', 'Kil': '8000ffe0', 'Rash': '801fffff'}    d3 = {key: d2[key] - d1.get(key, 0) for key in d2}   print(d3)  This is not working as it is giving type error:  TypeError: unsupported operand type(s) for -: 'str' and 'str'
9833
How do I convert a hex string to an int in Python?   I may have it as "0xffff" or just "ffff".
94538
It's easy to get the value of a key from a .NET generic Dictionary:  Dictionary&lt;int, string&gt; greek = new Dictionary&lt;int, string&gt;(); greek.Add(1, "Alpha"); greek.Add(2, "Beta"); string secondGreek = greek[2];  // Beta   But trying to get the keys given a value is not as straightforward because there could be multiple keys:  int[] betaKeys = greek.WhatDoIPutHere("Beta");  // expecting single 2
72597
How would i create a multi value Dictionary in c#?  E.g. Dictionary&lt;T,T,T&gt; where the first T is the key and other two are values.  so this would be possible: Dictionary&lt;int,object,double&gt;  Thanks
1436
Imagine that you have the following list. keys = ['name', 'age', 'food'] values = ['Monty', 42, 'spam']  What is the simplest way to produce the following dictionary? a_dict = {'name': 'Monty', 'age': 42, 'food': 'spam'}
5171
Here is the dictionary I have  propertyList = {     "id":           "int",     "name":         "char(40)",      "team":         "int",     "realOwner":    "int",      "x":            "int",     "y":            "int",      "description":  "char(255)",      "port":         "bool",     "secret":       "bool",     "dead":         "bool",     "nomadic":      "bool",      "population":   "int",     "slaves":       "int", }   But when I print it out with "\n".join(myDict) I get this  name nomadic dead port realOwner secret slaves team y x population id description   I know that a dictionary is unordered but it comes out the same every time and I've no idea why.
26627
In , it seems that [[:digit:]] = [0-9] = \d.    What are the circumstances where they do not equal? What is the difference?  After some research, I think one difference is that bracket expression [:expr:] is locale dependent.
89256
I want to assign a class attribute via a string object - but how?  Example:  class test(object):   pass  a = test() test.value = 5 a.value # -&gt; 5 test.__dict__['value'] # -&gt; 5  # BUT: attr_name = 'next_value'  test.__dict__[attr_name] = 10 # -&gt; 'dictproxy' object does not support item assignment
32263
Can you please tell me how much is (-2) % 5? According to my Python interpreter is 3, but do you have a wise explanation for this?  I've read that in some languages the result can be machine-dependent, but I'm not sure though.
81320
I am trying to add key value pair in the below JSON object, but it is getting added in the wrong way, is there any way i can add to each object a new  key value pair, that will help me to complete the req. JSON as follow : var object =[       {          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;       } ]  code i am using to add the new key value pair : for (let i = 0; i &lt; object.length; i++) {             object[i]['ABC'] = [i];         }  Actually expected should be: var object =[       {          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;,          &quot;ABC&quot;: &quot;0&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;,          &quot;ABC&quot;: &quot;1&quot;                 },       {          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;          &quot;ABC&quot;: &quot;2&quot;       } ]  the final value i am getting as below: [&quot;0&quot;:{          &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;,           },    &quot;1&quot;:{          &quot;asdf&quot;:&quot;&quot;,          &quot;fdrtf&quot;:&quot;869966&quot;,          &quot;hdhfhfh&quot;:&quot;utytut&quot;,          &quot;Cat&quot;:&quot;A&quot;              },    &quot;2&quot;:{        &quot;hjhj&quot;:&quot;&quot;,          &quot;hfhfhf&quot;:&quot;h&quot;,          &quot;hhfh&quot;:&quot;hfjfhdj&quot;,          &quot;cat&quot;:&quot;B&quot;    }   ]  kindly someone help me out to achieve this
68354
Is there anyway to get tuple operations in Python to work like this:  &gt;&gt;&gt; a = (1,2,3) &gt;&gt;&gt; b = (3,2,1) &gt;&gt;&gt; a + b (4,4,4)   instead of:  &gt;&gt;&gt; a = (1,2,3) &gt;&gt;&gt; b = (3,2,1) &gt;&gt;&gt; a + b (1,2,3,3,2,1)   I know it works like that because the __add__ and __mul__ methods are defined to work like that. So the only way would be to redefine them?
32655
I have a Python  object. What is the best way to subtract one day?
92538
I'd like to create a Dictionary object, with string Keys, holding values which are of a generic type. I imagine that it would look something like this:  Dictionary&lt;string, List&lt;T&gt;&gt; d = new Dictionary&lt;string, List&lt;T&gt;&gt;();     And enable me to add the following:  d.Add("Numbers", new List&lt;int&gt;()); d.Add("Letters", new List&lt;string&gt;());   I know that I can do it for a list of strings, for example, using this syntax:  Dictionary&lt;string, List&lt;string&gt;&gt; d = new Dictionary&lt;string, List&lt;string&gt;&gt;(); d.Add("Key", new List&lt;string&gt;());   but I'd like to do it for a generic list if possible...  2 questions then:   Is it possible? What's the syntax?   Many thanks, Jon
82341
example:  a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works   Python being (very) object oriented, I don't understand why the 'len' function isn't inherited by the object.  Plus I keep trying the wrong solution since it appears as the logical one to me
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?
103808
I saw some questions about "double subscript" but I have a weird situation. I have the following parts in my code:    and...    I have used almost the same subscripts in both of them, but the latter one gives a "double subscript" error while the first one works fine. What am I missing there? What is the reason for that error?  Here is my error bar:
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?
16381
I would want to do something like:  &gt;&gt;&gt; lst = [1, 2, 3, 4, 5] &gt;&gt;&gt; lst.find(lambda x: x % 2 == 0) 2 &gt;&gt;&gt; lst.findall(lambda x: x % 2 == 0) [2, 4]   Is there anything nearing such behavior in Python's standard libraries?  I know it's very easy to roll-your-own here, but I'm looking for a more standard way.