<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/python/tags/dictionary</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Sun, 19 May 2013 12:47:02 GMT</pubDate>
<item>
<title>(Python) Python - Dictionary - Does key exist? - denakitan</title>
<link>http://snipplr.com/view/59298/python--dictionary--does-key-exist/</link>
<description><![CDATA[ <p>Snippet to verify whether or not a key exists in a python dictionary.</p> ]]></description>
<pubDate>Fri, 30 Sep 2011 23:42:19 GMT</pubDate>
<guid>http://snipplr.com/view/59298/python--dictionary--does-key-exist/</guid>
</item>
<item>
<title>(Python) Swapping keys and values of a dictionary - Voil</title>
<link>http://snipplr.com/view/45464/swapping-keys-and-values-of-a-dictionary/</link>
<description><![CDATA[ <p>Based on the example by [Mark Pilgrim](http://diveintopython3.org/about.html).</p> ]]></description>
<pubDate>Wed, 08 Dec 2010 21:00:41 GMT</pubDate>
<guid>http://snipplr.com/view/45464/swapping-keys-and-values-of-a-dictionary/</guid>
</item>
<item>
<title>(Python) qPyDict - vkolev</title>
<link>http://snipplr.com/view/43446/qpydict/</link>
<description><![CDATA[ <p>It's absolutly the same as the gDict, that I wrote with pyGTK2, but now with Qt4 GUI just for testing.</p> ]]></description>
<pubDate>Wed, 03 Nov 2010 02:21:43 GMT</pubDate>
<guid>http://snipplr.com/view/43446/qpydict/</guid>
</item>
<item>
<title>(Python) tiles_visited - anosognosia</title>
<link>http://snipplr.com/view/35601/tilesvisited/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 08 Jun 2010 11:38:57 GMT</pubDate>
<guid>http://snipplr.com/view/35601/tilesvisited/</guid>
</item>
<item>
<title>(Python) sorting a dictionary - magicrebirth</title>
<link>http://snipplr.com/view/34623/sorting-a-dictionary/</link>
<description><![CDATA[ <p>Dictionaries cant be sorted, so you need to transform it into a list and sort that one!</p> ]]></description>
<pubDate>Mon, 17 May 2010 08:03:48 GMT</pubDate>
<guid>http://snipplr.com/view/34623/sorting-a-dictionary/</guid>
</item>
<item>
<title>(Python) dict.items vs dict.iteritems - magicrebirth</title>
<link>http://snipplr.com/view/34617/dictitems-vs-dictiteritems/</link>
<description><![CDATA[ <p>When is it appropriate to use dict.items() vs dict.iteritems?


Also, when is it appropriate to use range() vs xrange(). From my
understanding, xrange() essentially gives you an iterator across a
range, so it should be used when iterating. Should you only use
range() when want to physically store the range as a list?</p> ]]></description>
<pubDate>Mon, 17 May 2010 06:49:51 GMT</pubDate>
<guid>http://snipplr.com/view/34617/dictitems-vs-dictiteritems/</guid>
</item>
<item>
<title>(Python) 'Dictionary Comprehensions' - magicrebirth</title>
<link>http://snipplr.com/view/34616/dictionary-comprehensions/</link>
<description><![CDATA[ <p>Although Python doesn't have built-in dictionary comprehensions, you can do something pretty close with little mess or code. Just use .iteritems() to turn your dict into a list, throw it in a generator expression (or list comprehension), and then cast that list back into a dict.

For example, say I have a dictionary of name:email pairs, and I want to create a dictionary of name:is_email_at_a_dot_com pairs:</p> ]]></description>
<pubDate>Mon, 17 May 2010 06:34:30 GMT</pubDate>
<guid>http://snipplr.com/view/34616/dictionary-comprehensions/</guid>
</item>
<item>
<title>(Python) Dicts to Lists / Lists to Dicts - magicrebirth</title>
<link>http://snipplr.com/view/34615/dicts-to-lists--lists-to-dicts/</link>
<description><![CDATA[ <p>Turning a dictionary into a list or an iterator is easy. To get a list of keys, you can just cast the dict into a list. It's cleaner, though to call .keys() on the dictionary to get a list of the keys, or .iterkeys() to get an iterator. Similarly, you can call .values() or .itervalues() to get a list or iterator of dictionary values. Remember though, that dicts are inherently unordered and so these values won't be in any meaningful order.

To preserve both keys and values, you can turn a dict into a list or iterator of 2-item tuples by using .items() or .iteritems(). This is something that you'll probably do a lot, and isn't very exciting:</p> ]]></description>
<pubDate>Mon, 17 May 2010 06:33:09 GMT</pubDate>
<guid>http://snipplr.com/view/34615/dicts-to-lists--lists-to-dicts/</guid>
</item>
<item>
<title>(Python) Creating Dictionaries - magicrebirth</title>
<link>http://snipplr.com/view/34614/creating-dictionaries/</link>
<description><![CDATA[ <p>Any keyword arguments you pass to the dict constructor are added to the newly created dictionary before returning. Of course, you are limited to the keys that can be made into keyword arguments: valid Python variable names.</p> ]]></description>
<pubDate>Mon, 17 May 2010 06:30:32 GMT</pubDate>
<guid>http://snipplr.com/view/34614/creating-dictionaries/</guid>
</item>
<item>
<title>(Python) Python: lambda in a dictionary - magicrebirth</title>
<link>http://snipplr.com/view/25257/python-lambda-in-a-dictionary/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 22 Dec 2009 15:31:26 GMT</pubDate>
<guid>http://snipplr.com/view/25257/python-lambda-in-a-dictionary/</guid>
</item>
<item>
<title>(Python) Python: using Pickle to save a dictionary - magicrebirth</title>
<link>http://snipplr.com/view/25244/python-using-pickle-to-save-a-dictionary/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 22 Dec 2009 15:17:53 GMT</pubDate>
<guid>http://snipplr.com/view/25244/python-using-pickle-to-save-a-dictionary/</guid>
</item>
<item>
<title>(Python) Python: from two lists to a dictionary - magicrebirth</title>
<link>http://snipplr.com/view/25242/python-from-two-lists-to-a-dictionary/</link>
<description><![CDATA[ <p>create a dictionary from the data in two lists</p> ]]></description>
<pubDate>Tue, 22 Dec 2009 15:10:27 GMT</pubDate>
<guid>http://snipplr.com/view/25242/python-from-two-lists-to-a-dictionary/</guid>
</item>
<item>
<title>(Python) Print keys, values for dictionary - dorseye</title>
<link>http://snipplr.com/view/18752/print-keys-values-for-dictionary/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sun, 23 Aug 2009 19:09:21 GMT</pubDate>
<guid>http://snipplr.com/view/18752/print-keys-values-for-dictionary/</guid>
</item>
<item>
<title>(Python) Pass list to dict() - dorseye</title>
<link>http://snipplr.com/view/18493/pass-list-to-dict/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Wed, 19 Aug 2009 00:12:59 GMT</pubDate>
<guid>http://snipplr.com/view/18493/pass-list-to-dict/</guid>
</item>
<item>
<title>(Python) Regular Expression Key Clean - cthulhupunk0</title>
<link>http://snipplr.com/view/15709/regular-expression-key-clean/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 08 Jun 2009 17:46:42 GMT</pubDate>
<guid>http://snipplr.com/view/15709/regular-expression-key-clean/</guid>
</item>
<item>
<title>(Python) Aggregator class for a dictionary of individual items - cthulhupunk0</title>
<link>http://snipplr.com/view/15701/aggregator-class-for-a-dictionary-of-individual-items/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 08 Jun 2009 12:33:54 GMT</pubDate>
<guid>http://snipplr.com/view/15701/aggregator-class-for-a-dictionary-of-individual-items/</guid>
</item>
<item>
<title>(Python) Dictionary Class - kangell</title>
<link>http://snipplr.com/view/5753/dictionary-class/</link>
<description><![CDATA[ <p>This bit of code allows you to turn code that looks like this:

x = {'foo':1, 'bar':2 }
x['foo'] = 3

Into this:
x = dictclass( {'foo':1, 'bar':2 } )
x.foo = 3</p> ]]></description>
<pubDate>Tue, 08 Apr 2008 23:06:14 GMT</pubDate>
<guid>http://snipplr.com/view/5753/dictionary-class/</guid>
</item>
<item>
<title>(Python) Python - Cattura tutti i links  - whitetiger</title>
<link>http://snipplr.com/view/1642/python--cattura-tutti-i-links-a-href/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 09 Nov 2006 23:55:53 GMT</pubDate>
<guid>http://snipplr.com/view/1642/python--cattura-tutti-i-links-a-href/</guid>
</item>
<item>
<title>(Python) Python - Uso di wx.PostEvent - whitetiger</title>
<link>http://snipplr.com/view/1640/python--uso-di-wxpostevent/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 09 Nov 2006 23:55:52 GMT</pubDate>
<guid>http://snipplr.com/view/1640/python--uso-di-wxpostevent/</guid>
</item>
<item>
<title>(Python) Python - Stampa i links di una pagina HTML - whitetiger</title>
<link>http://snipplr.com/view/1641/python--stampa-i-links-di-una-pagina-html/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 09 Nov 2006 23:55:52 GMT</pubDate>
<guid>http://snipplr.com/view/1641/python--stampa-i-links-di-una-pagina-html/</guid>
</item>
</channel>
</rss>