Append or Add to string of specific index
<p>I have a list of class objects 'x'. I am trying to create a new list by appending certain attribute values of the objects but I would like to append more that one attribute per index. For example, what I currently get:</p>

<pre><code>x = blah.values()

newList = []
for i in range(len(x)):
    if x[i].status == 'ACT':
        newList.append(str(x[i].full_name)),
        newList.append(str(x[i].team))
else:
    pass

print newList
</code></pre>

<p>The above code provides me with something like:</p>

<pre><code>['Victor Cruz', 'NYG', 'Marcus Cromartie', 'SF',....]
</code></pre>

<p>What I am trying to get:</p>

<pre><code>['Victor Cruz NYG', 'Marcus Cromartie SF',....]
</code></pre>

<p>How can I append more than one attribute per index? Hope this make sense, I can try to further elaborate if needed, thanks!</p>

<p>You can use <code>.format()</code> in order to format your string. Notice the space between <code>{} {}</code></p>

<pre><code>for i in range(len(x)):
    if x[i].status == 'ACT':
        newList.append("{} {}".format(x[i].full_name,x[i].team) )
</code></pre>

<p>Another way is using <code>"%s" % string</code> notation</p>

<pre><code>newList.append("%s %s" % (str(x[i].full_name),str(x[i].team)))
</code></pre>

<p>Another example of <code>.format</code> using.</p>

<pre><code>"{} is {}".format('My answer', 'good')
&gt;&gt;&gt; "My answer is good"
</code></pre>

python python-2.7