tail -f findings.out

« Convenient OS and hardware summary information

Recursively ignoring multiple file patterns in subversion »

Python Tip: Create a test dictionary quickly

Sometimes you just want to play around with dictionaries in Python. Alright, probably not very often. But when you do, you might just want any old dictionary, and quickly if possible. Typing lots of quotes and commas and curly braces isn’t very suitable to this. So here is a fun way to make a dictionary, just add a sentence without punctuation (any set of space separated words will do, but it might as well be interesting):

test_dict = dict(enumerate('Beautiful is better than ugly'.split()))
test_dict
{0: 'Beautiful', 1: 'is', 2: 'better', 3: 'than', 4: 'ugly'}

Can’t get much easier than that.

Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

Post to Twitter Post to Delicious Post to Digg Post to Reddit

Possibly Related (no promises):

  1. A better way to search for methods of Python objects
  2. Printing tabular data attractively in Python

Related posts brought to you by Yet Another Related Posts Plugin.

Tags: , ,
January 4, 2009 - 10:55 PM
Leave a reply

Subscribe without commenting

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.