say i have a dictionary in a file in the following format:
{'a': 1, 'b': 2, 'c': 3}
How do I format it 'tidily' in PyCharm? e.g.
{
'a': 1,
'b': 2,
'c': 3
}
Use format() function to format dictionary print in Python. Its in-built String function is used for the purpose of formatting strings according to the position. Python Dictionary can also be passed to format() function as a value to be formatted.
The dialog appears when you press Ctrl+Alt+Shift+L in the editor of the current file. If you choose Code | Reformat Code from the main menu or press Ctrl+Alt+L , PyCharm tries to reformat the source code of the specified scope automatically.
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 some selection, map literals will be formatted properly (like asked in the question).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With