Search code examples
python-3.xright-justified

How to do GOOD right justify in python? the string before str.rjust() has various length


right just

this is how i have it printed now, but i want all numbers to be one same level, but i can't do it, because emails have different lengths - hotmail.com, mail.com etc

my code:

def count_domains(date, emails):

print(date)
my_emails = []
for email in emails:
    current_email = email.split("@", 2)[1]
    my_emails.append(current_email)

unique_emails = list(set(my_emails))    
for x in range(len(unique_emails)):        
    print( str(unique_emails[x]).rjust(2) + " : " +     str(my_emails.count(unique_emails[x])).rjust(4))

Solution

  • What about something like this:

    print((str(unique_emails[x]) + ": ").ljust(20) +
          str(my_emails.count(unique_emails[x])).rjust(4))