Created
          September 12, 2019 03:12 
        
      - 
      
- 
        Save joshschmelzle/0a2de4b22b81523570caa1490f8e8498 to your computer and use it in GitHub Desktop. 
    Center align values on a specific character with Python
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def at_aligned(seq): | |
| snums = [str(n) for n in seq] | |
| ats = [len(s.split('@', 1)[0]) for s in snums] | |
| m = max(ats) | |
| return [' '*(m - d) + s for s, d in zip(snums, ats)] | |
| channelInfo = ["36@160", | |
| "1@20", | |
| "161@40", | |
| "161@40", | |
| "100@160", | |
| "11@20", | |
| "157@40-"] | |
| for x in at_aligned(channelInfo): | |
| print(x) | |
| # Results: | |
| # 36@160 | |
| # 1@20 | |
| # 161@40 | |
| # 161@40 | |
| # 100@160 | |
| # 11@20 | |
| # 157@40- | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment