I want to put tickers in brackets
<p>I want to put AEM into brackets, so that text will look like: Agnico Eagle Mines Limited (AEM)</p>

<pre><code>text = "Agnico Eagle Mines Limited AEM"
def add_brackets(test):
     for word in test:
         if word.isupper():
             word = "(" + word + ")"
     print(test)

print(add_brackets(text))
</code></pre>

<p>What's wrong with the code? I get the original text. </p>

<p>Two things, 1 you are checking per character, not per word. 2 you are not modifying <code>text</code> you are just setting <code>word</code> and not doing anything with it. </p>

<pre><code>text = "Agnico Eagle Mines Limited AEM"


def add_brackets(test):
    outstr = ""
    for word in test.split(" "):
        if word.isupper():
            outstr += " (" + word + ")"
        else:
            outstr += " " + word
    return outstr.strip()


print(add_brackets(text))
</code></pre>

<p>Edit: Fancier</p>

<pre><code>text = "Agnico Eagle Mines Limited AEM"


def add_brackets(test):
    return " ".join(["({})".format(word) if word.isupper() else word for word in test.split(" ")])

print(add_brackets(text))
</code></pre>

python