>>> d = {'four': {'six': 6, 'five': 5}, 'three': [3, 33, 333], 'two': 2, 'one': 1}
Print out to console only first level of dictionary like this:
>>> {'four': {...}, 'one': 1, 'three': [...], 'two': 2}

  • print(d)

  • Correct answer

    from pprint import pprint
    pprint(d, depth=1)

  • from pprint import pprint
    pprint(d)

This question is one of 8 in Python tricks. Test yourself on all of them.

Practice quiz Flashcards

Log in to add an explanation.

Advertisement