What is the proper way to format a multi-line dict in Python?

后端 未结 7 1483
天命终不由人
天命终不由人 2020-11-29 16:19

In Python, I want to write a multi-line dict in my code. There are a couple of ways one could format it. Here are a few that I could think of:

  1. mydic         
    
    
            
7条回答
  •  甜味超标
    2020-11-29 16:47

    Since your keys are strings and since we are talking about readability, I prefer :

    mydict = dict(
        key1 = 1,
        key2 = 2,
        key3 = 3,
    )
    

提交回复
热议问题