I have the following dictionary. {'VVD': ['male', 'female', 'female', 'female', 'female', 'male', 'male', 'female', 'male', 'female', 'male', 'male', 'female', 'female', 'male', 'male', 'female', 'male', 'male', 'female', 'male', 'male', 'male', 'male', 'female', 'male', 'female', 'male', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'male', 'female', 'female', 'male', 'female', 'male', 'male', 'male', 'male', 'male', 'male', 'female', 'female', 'male', 'female', 'male', 'female', 'male', 'male', 'male', 'male', 'male', 'female', 'female', 'female', 'female', 'male', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'male'], 'PVV (Partij voor de Vrijheid)': ['male', 'female', 'male', 'male', 'female', 'male', 'male', 'male', 'female', 'male', 'male', 'female', 'male', 'male', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'male', 'female', 'female', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'male', 'female', 'male', 'male', 'male', 'male']}  I want to get the first 30 values per key. How can I do this?
106
I need a good explanation (references are a plus) on Python's slice notation.   To me, this notation needs a bit of picking up.   It looks extremely powerful, but I haven't quite got my head around it.
4615
Given a dictionary like so:  my_map = {'a': 1, 'b': 2}   How can one invert this map to get:  inv_map = {1: 'a', 2: 'b'}
117864
I have the file:  key value  blah blah blah blah blahblah man1 boy1 blah blah man1 boy2 man1 boy1   I  do this to remove duplicate lines:  awk '/man1/ { print $1,$2} ' file | awk '!x[$0]++'   and the command take the first line and ignore other lines  man1 boy1  man1 boy2   but I want to ignore all lines except the last line:  man1 boy2  man1 boy1   as ramesh said I want something like:  cat filename blah blah blah blah blahblah man1 boy1 blah blah man1 boy2 man1 boy1 man1 boy2 man1 boy3 man1 boy4 man1 boy2   the desired output   man1 boy1 man1 boy3 man1 boy4 man1 boy2
2050
Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index (1) in Python?
113304
I have:  Name PhoneNo JOHN 555555 JOHN 555554 MIKE 111111 MIKE 122222   I want to display output like:  Name PhoneNo JOHN 555555      555554 MIKE 111111      111112
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
79724
I'm looking for something similar to this, or other:  len(bpy.context.selected_objects)
7281
I have a list of dictionaries and want each item to be sorted by a specific value. Take into consideration the list: [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]  When sorted by name, it should become: [{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}]
36635
I have two tables that represent a list of urls and their related word indexes. Here are the table definitions for reference.  desc urllist; +-------+---------------------+------+-----+---------+----------------+ | Field | Type                | Null | Key | Default | Extra          | +-------+---------------------+------+-----+---------+----------------+ | id    | bigint(20) unsigned | NO   | PRI | NULL    | auto_increment | | url   | text                | NO   |     | NULL    |                | +-------+---------------------+------+-----+---------+----------------+   and  desc wordlocation; +----------+---------------------+------+-----+---------+-------+ | Field    | Type                | Null | Key | Default | Extra | +----------+---------------------+------+-----+---------+-------+ | urlid    | bigint(20) unsigned | NO   |     | NULL    |       | | wordid   | bigint(20) unsigned | NO   |     | NULL    |       | | location | int(10) unsigned    | NO   |     | NULL    |       | +----------+---------------------+------+-----+---------+-------+   The software app is a web spider. It crawls a list of urls, extracts those urls, and inserts these into the urllist table. Then, an indexer checks to see what urls have not yet been indexed, and then proceeds to index said urls.  Here is the query I am using to find items in the left table (urllist) that have not yet been indexed in the right table (wordlocation). This query is as suggested on the :  select * from urllist ul  left join wordlocation wl on ul.id = wl.urlid  where wl.urlid IS NULL;   As of this writing my test database has only 600 indexed urls, and the wordlocation table has 1.3 million rows.  However, my CPU is at 100%, and the longest I've waited to see if the query would complete is a half hour (which, it never did by the way).  To be thorough, here is the explanation of the query:  explain select * from urllist ul left join wordlocation wl on ul.id = wl.urlid where wl.urlid IS NULL; +----+-------------+-------+------+---------------+------+---------+------+---------+-------------------------+ | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows    | Extra                   | +----+-------------+-------+------+---------------+------+---------+------+---------+-------------------------+ |  1 | SIMPLE      | ul    | ALL  | NULL          | NULL | NULL    | NULL |   50364 |                         | |  1 | SIMPLE      | wl    | ALL  | NULL          | NULL | NULL    | NULL | 1351371 | Using where; Not exists | +----+-------------+-------+------+---------------+------+---------+------+---------+-------------------------+   I need this query to finish in seconds, not minutes. Also, I'm worried about scalability. I have 40,000 unique urls that are waiting to be added to the index, so how do I take that into consideration with my table and query design? 400,000 urls?  Just a couple notes about my decisions on the current table structure.  I have no intention of stopping at 400,000 urls, but perhaps bigint(20) is a bit overzealous?   Url as text is for more practical reasons. I index a lot of Asian and other foreign language domains which do not appear as their equivalent Kanji or other characters in the database and frequently take more than 255 characters.  I'm using MySQL. I'm definitely open to suggestions as to better table and query design. Please let me know if I can provide more information.
3104
I'm stuck on what how to continue. I know I'm missing a few steps but this is what I have so far. Thank you in advance!   ¬Cube(b) → Small(b) Small(c) → (Small(d) ∨ Small(e))  Small(d) → ¬Small(c) Cube(b) → ¬Small(e)   Small(c)   ¬Small(b)   ¬Cube(b) Small(b) (→ Elim 1,7) ⊥ (⊥intro 6, 8)    10.Cube(b) (¬Intro 7-9)   ¬Small(e) (→ Elim 4,10)     Goal: Small(c) → Small(b)
1477
How can I get the Cartesian product (every possible combination of values) from a group of lists?  Input:   somelists = [    [1, 2, 3],    ['a', 'b'],    [4, 5] ]   Desired output:  [(1, 'a', 4), (1, 'a', 5), (1, 'b', 4), (1, 'b', 5), (2, 'a', 4), (2, 'a', 5) ...]
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 :)
63309
I just saw this behaviour and I'm a bit surprised by it...  If I add 3 or 4 elements to a Dictionary, and then do a "For Each" to get all the keys, they appear in the same order I added them.  The reason this surprises me is that a Dictionary is supposed to be a HashTable internally, so I expected things to come out in ANY order (ordered by the hash of the key, right?)  What am I missing here? Is this a behaviour I can count on?  EDIT: OK, I thought already of many of the reasons why this might happen (like the separate list to entries, whether this is a coincidence, etc). My question is, does anyone know how this really works?
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.)
70618
So I was writing up a simple binary tree in Python and came across [...]  I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding when accessed is something I'm completely lost to, however   &gt;&gt;&gt; a [[[[[], [], 8, 3], [[], [], 3, 2], 6, 3], [], 1, 4], [[], [], -4, 2], 0, 0] &gt;&gt;&gt; Keys(a)#With a+b [0, 1, 6, 8, 3, -4] &gt;&gt;&gt; Keys(a)#With [a,b] [8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...]] &gt;&gt;&gt; Keys(a)[1]#?? [8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...], 8, [...], [...], 3, [...], [...], 6, [...], [...], 1, [...], [...], -4, [...], [...], 0, [...], [...]]     Version using a+b  def Keys(x,y=[]):     if len(x):y+=[x[2]]+Keys(x[0],y)+Keys(x[1],y)#Though it seems I was using y=y[:]+, this actually outputs an ugly mess     return y   version using [a,b]  def Keys(x,y=[]):     if len(x):y+=[x[2],Keys(x[0],y),Keys(x[1],y)]     return y   So what exactly is [...]?
78502
I use Thunderbird with two sets of dictionaries: English and Spanish. In the spell checker menu I find about 30 localized dictionaries (all Spanish-speaking countries, and for English: US, England, Canada).  It's quite annoying that every time I need to look for the single proper dictionary, I see all this heap of other dictionaries (useless for me).  Is there any way to remove the unused dictionaries from the menu and leave 2 or 3 that I really use?
19201
What is the best way to extend a dictionary with another one while avoiding the use of a for loop? For instance: &gt;&gt;&gt; a = { &quot;a&quot; : 1, &quot;b&quot; : 2 } &gt;&gt;&gt; b = { &quot;c&quot; : 3, &quot;d&quot; : 4 } &gt;&gt;&gt; a {'a': 1, 'b': 2} &gt;&gt;&gt; b {'c': 3, 'd': 4}  Result: { &quot;a&quot; : 1, &quot;b&quot; : 2, &quot;c&quot; : 3, &quot;d&quot; : 4 }  Something like: a.extend(b)  # This does not work