PyCharm: format the dictionary in neat order?

let's say I have a dictionary in a file in the following format:

{'a': 1, 'b': 2, 'c': 3} 

How do I format "neatly" in PyCharm? eg

 { 'a': 1, 'b': 2, 'c': 3 } 
+14
source share
2 answers

Go to

 Editor -> Code style -> Python -> Wrapping and Braces -> Dictionary literals. 

Set Wrap always instead of Wrap if long .

Then, if you reformat the file or any fragment, the map literals will be correctly formatted (as indicated in the question).

enter image description here

+14
source

You need to select the dict structure inside PyCharm, then [Code]> [Reformat Code ...], then make sure the "Selected text" option is selected and click "Run."

0
source

All Articles