0

I have a large (~10 elements) list of integers that I wish to interpolate into a string. This seems like an ideal use case for the splat operator, so I'd like to be able to do something like this:

"""[latex]$\begin{bmatrix}
%d & %d \\ %d & %d\end{bmatrix}
\times
\begin{bmatrix}
%d & %d \\ %d & %d
\end{bmatrix} $[/latex]""" % (*lst)
                              ^^^^ SyntaxError: invalid syntax

What is a clean, syntactically valid way to achieve this?

pseudosudo
  • 6,270
  • 9
  • 40
  • 53
  • Ignacio has given the correct answer, but it is important to note that this also just an invalid usage of the * splat operator in Python. https://stackoverflow.com/questions/45346116/where-are-pythons-splat-operators-and-valid – Evan Feb 09 '18 at 18:46

1 Answers1

2

str.__mod__ takes a tuple.

'''...''' % tuple(lst)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358