Skip to content
Advertisement

Python: Replace characters in string at different positions with arguments

It’s a simple question. I have a generic string and I want to replace an asterisk * with arguments provided.

JavaScript

If I shall give two arguments ('Berlin','Germany'), I should get

JavaScript

It’s an easy problem, and I can solve it, but I am looking for one line solution where every positional argument replaces the corresponding *. I think, I have seen something of this type (*) ...(*), but can’t recollect. Someone has any idea?

Advertisement

Answer

You have many ways to do this, a simple one if you have tuples of 2 elements:

JavaScript

or

JavaScript

output: 'Berlin is the capital of Germany'

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement