String Formatting

  • + 0 comments

    Try this:

    def print_formatted(number):
        width = len(bin(number)[2:])
        nList = [[i, oct(i)[2:], hex(i)[2:], bin(i)[2:]] for i in range(1, number+1)]
        nList = [map(lambda x:str(x).rjust(width).upper(), item) for item in nList]
        nList = [' '.join(item) for item in nList]
        nList = '\n'.join(nList)
        print(nList)