Skip to content

Instantly share code, notes, and snippets.

@joshschmelzle
Created September 12, 2019 03:12
Show Gist options
  • Save joshschmelzle/0a2de4b22b81523570caa1490f8e8498 to your computer and use it in GitHub Desktop.
Save joshschmelzle/0a2de4b22b81523570caa1490f8e8498 to your computer and use it in GitHub Desktop.
Center align values on a specific character with Python
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