write unicode objects from loop to list in Python
<p>I have a loop that returns me unicode objects:</p>

<pre><code>for i in X:
print i

Output:  

  A
  B
  C
  ...
  Z
</code></pre>

<p>How can I make a list of these objects to get the folloving?</p>

<pre><code>['A', 'B', ..., 'Z']
</code></pre>

<p>If they were numbers, i'd do</p>

<pre><code>for i in X:
y=[]
i.append(y)
</code></pre>

<p>but here i get the error </p>

<pre><code>AttributeError: 'unicode' object has no attribute 'append'
</code></pre>

<p>try this:</p>

<p><code>output_list = [y for y in x]</code></p>

<p>in your loop:</p>

<pre><code>for i in X:
    i.append(X)
</code></pre>

<p>it takes each item in <code>X</code>, which are unicode chars, and tries to append the whole <code>X</code> object to it.</p>

<p>I think what you're wanting to do is like this:</p>

<pre><code>l = []
for i in X:
    l.append(i)
print l
</code></pre>

<p>but this can be accomplished with simple list comprehension showed above.</p>

python list unicode append