-2
a = [
    [1,212,-13],
    [41,5,614],
    [7,8,91]
]
print "\n".join(
    map(
        lambda row:
            " ".join(map(
                lambda y: "%4d" % y,
                row
            )),
        a
    )
)
# OUT:
#   1  212  -13
#  41    5  614
#   7    8   91

On the lambda y: %4d % y line, I am wondering what the % y is doing. I understand the "%4d" is giving 4 units of space.

Thank you for your help

  • 1
    It's a string operator, not part of the lambda expression (at least, it's only a part of the lambda expression insofar as it is part of the expression that forms the body; it's not specific to the lambda expression). `"%4d" % 5 == ' 5'` – chepner May 06 '21 at 18:21

1 Answers1

1

It does the same thing as:

'{}'.format(string)
# or
f'{string}'

The %d means int, and %s means string.

Here is a site explaining it What does %s mean in a Python format string?

Have a nice day
  • 1,007
  • 5
  • 11