A constant is a value or binding intended to remain unchanged within a computation or defined scope. Giving repeated data one name makes a design easier to update and reduces the chance of inconsistent edits. section 1.3.1 section 1.7.1
One delimiter, many output lines
Instead of repeating a comma in every output expression, define DELIMITER once and reuse it: DELIMITER = '\t'; then join each row with DELIMITER. Switching back to commas requires changing one assignment rather than searching through several lines. section 1.3.1
DELIMITER = '\t' print(DELIMITER.join([col1_name, col2_name, col3_name, col4_name])) print(DELIMITER.join([first_val, second_val, third_val, fourth_val]))
Compare repeated separators with a named delimiter and join-based output. section 1.3.1
Precomputing reusable data
State capitals can be calculated once and stored for later use: US_CAPITALS_BY_STATE holds the mapping, while US_CAPITALS stores its sorted values. This avoids repeating the same calculation without sacrificing readability. section 1.7.1
Listing 1.3. Refactored code reveals a more concise solution
US_CAPITALS_BY_STATE = {'Alabama': 'Montgomery', ...} #1
US_CAPITALS = sorted(US_CAPITALS_BY_STATE.values()) #2
See the refactoring from a reusable function to module-level data computed once. section 1.7.1






