Appending item to lists - python

Posted by ariel on Stack Overflow See other posts from Stack Overflow or by ariel
Published on 2010-03-24T05:23:23Z Indexed on 2010/03/24 5:33 UTC
Read the original article Hit count: 166

Filed under:
|

I have a list lets say a=[[1,2],[3,4],[5,6]]. I want to add to each item in a the char 'a'. when I use a=[x.append('a') for x in a] it return [None,None,None]. But if I use a1=[x.append('a') for x in a] then it do someting odd. a and not a1 is [[1,2,a],[3,4,a],[5,6,a]]. I don't understand why the first return [None, None, None] nor why the second works on a.

© Stack Overflow or respective owner

Related posts about python

Related posts about for-loop