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.
Possibly Related (no promises):
Related posts brought to you by Yet Another Related Posts Plugin.







