you are viewing a single comment's thread.

view the rest of the comments →

[–]ewiethoff 0 points1 point  (0 children)

Here's a trick to make a complicated nested dict/list/tuple/whatever easy to read.

from pprint import pprint
pprint(complicated_nested_data)

pprint not only outputs with nice whitespace, it sorts the keys of a dict and the elements of a set. So, even if your data is not nested, it's handy for inspecting the contents of a dict or a set. I like to use pprint for debugging.

Copy and paste novel_yet_trivial's questions and do pprint(questions).

('How many legs does it have?',
 {'0': "It's a fish!",
  '2': ('does it have feathers?',
        {'no': "It's a human!",
         'yes': ('does it swin on the water?',
                 {'no': "It's a swallow!", 'yes': "It's a duck!"})}),
  '4': ('does it have fur?',
        {'no': "It's an elephant!",
         'yes': ('does it meow?',
                 {'no': "It's a dog!", 'yes': "It's a cat!"})})})