Reputation: 185
As you can imagine I'm getting started with Python (sorry about for the noob question). I'm writing a code that uses some long dictionary entries and I'm struggling to make Python happy with the 80 characters limit.
Here is a snip of my dictionary:
"Hybrid functionals": {
"B1LYP": "The one - parameter hybrid functional with Becke '88 exchange and Lee - Yang - Parr correlation(25 % HF exchange)",
"B3LYP and B3LYP/G": "The popular B3LYP functional (20% HF exchange) as defined in the TurboMole program system and the Gaussian program system, respectively",
"O3LYP": "The Handy hybrid functional",
"X3LYP": "The Xu and Goddard hybrid functional",
"B1P": "The one-parameter hybrid version of BP86",
"B3P": "The three-parameter hybrid version of BP86",
"B3PW": "The three-parameter hybrid version of PW91",
"PW1PW": "One-parameter hybrid version of PW91",
"mPW1PW": "One-parameter hybrid version of mPWPW",
"mPW1LYP": "One-parameter hybrid version of mPWLYP",
"PBE0": "One-parameter hybrid version of PBE",
"PW6B95": "Hybrid functional by Truhlar",
"BHANDHLYP": "Half-and-half hybrid functional by Becke"},
So, what is the correct way to deal with extremely long strings in a dictionary?
Thanks guys
Upvotes: 1
Views: 2974
Reputation: 24281
Python has no "80 chars limit". It is a style recommendation, but you're free not to respect it. However, it can make your code harder to read, and your editor might warn you about these long lines.
One way to get around the problem is to use automatic string concatenation:
Multiple adjacent string or bytes literals (delimited by whitespace), possibly using different quoting conventions, are allowed, and their meaning is the same as their concatenation. Thus, "hello" 'world' is equivalent to "helloworld".
So, you could write your dict as:
{
"B1LYP": "The one - parameter hybrid functional with Becke '88"
" exchange and Lee - Yang - Parr correlation(25 % HF "
"exchange)",
...
Upvotes: 3